Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFileTimeCache.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmFileTimeCache.h"
4
5
#include <string>
6
#include <unordered_map>
7
#include <utility>
8
9
35
cmFileTimeCache::cmFileTimeCache() = default;
10
11
35
cmFileTimeCache::~cmFileTimeCache() = default;
12
13
bool cmFileTimeCache::Load(std::string const& fileName, cmFileTime& fileTime)
14
0
{
15
  // Use the stored time if available.
16
0
  {
17
0
    auto fit = this->Cache.find(fileName);
18
0
    if (fit != this->Cache.end()) {
19
0
      fileTime = fit->second;
20
0
      return true;
21
0
    }
22
0
  }
23
  // Read file time from OS
24
0
  if (!fileTime.Load(fileName)) {
25
0
    return false;
26
0
  }
27
  // Store file time in cache
28
0
  this->Cache[fileName] = fileTime;
29
0
  return true;
30
0
}
31
32
bool cmFileTimeCache::Remove(std::string const& fileName)
33
0
{
34
0
  return (this->Cache.erase(fileName) != 0);
35
0
}
36
37
bool cmFileTimeCache::Compare(std::string const& f1, std::string const& f2,
38
                              int* result)
39
0
{
40
  // Get the modification time for each file.
41
0
  cmFileTime ft1;
42
0
  cmFileTime ft2;
43
0
  if (this->Load(f1, ft1) && this->Load(f2, ft2)) {
44
    // Compare the two modification times.
45
0
    *result = ft1.Compare(ft2);
46
0
    return true;
47
0
  }
48
  // No comparison available.  Default to the same time.
49
0
  *result = 0;
50
0
  return false;
51
0
}
52
53
bool cmFileTimeCache::DifferS(std::string const& f1, std::string const& f2)
54
0
{
55
  // Get the modification time for each file.
56
0
  cmFileTime ft1;
57
0
  cmFileTime ft2;
58
0
  if (this->Load(f1, ft1) && this->Load(f2, ft2)) {
59
    // Compare the two modification times.
60
0
    return ft1.DifferS(ft2);
61
0
  }
62
  // No comparison available.  Default to different times.
63
0
  return true;
64
0
}