1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmFileTimeCache.h"
6 #include <unordered_map>
9 cmFileTimeCache::cmFileTimeCache() = default;
11 cmFileTimeCache::~cmFileTimeCache() = default;
13 bool cmFileTimeCache::Load(std::string const& fileName, cmFileTime& fileTime)
15 // Use the stored time if available.
17 auto fit = this->Cache.find(fileName);
18 if (fit != this->Cache.end()) {
19 fileTime = fit->second;
23 // Read file time from OS
24 if (!fileTime.Load(fileName)) {
27 // Store file time in cache
28 this->Cache[fileName] = fileTime;
32 bool cmFileTimeCache::Remove(std::string const& fileName)
34 return (this->Cache.erase(fileName) != 0);
37 bool cmFileTimeCache::Compare(std::string const& f1, std::string const& f2,
40 // Get the modification time for each file.
43 if (this->Load(f1, ft1) && this->Load(f2, ft2)) {
44 // Compare the two modification times.
45 *result = ft1.Compare(ft2);
48 // No comparison available. Default to the same time.
53 bool cmFileTimeCache::DifferS(std::string const& f1, std::string const& f2)
55 // Get the modification time for each file.
58 if (this->Load(f1, ft1) && this->Load(f2, ft2)) {
59 // Compare the two modification times.
60 return ft1.DifferS(ft2);
62 // No comparison available. Default to different times.