| // Copyright 2023 Google Inc. All Rights Reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #ifndef NINJA_STAT_CACHE_H_ |
| #define NINJA_STAT_CACHE_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "timestamp.h" |
| |
| /// Implement a cache for file path timestamps. |
| class StatCache { |
| public: |
| /// Constructor |
| StatCache(); |
| |
| /// Destructor |
| ~StatCache(); |
| |
| /// Enable caching of timestamps. If false (the default), the Stat() performs |
| /// a single stat() operation per file and no caching is performed. |
| void Enable(bool enabled); |
| |
| /// Mark a path as invalid. |
| void Invalidate(const std::string& path); |
| |
| /// Return the timestamp of a given file path. On error, set |*err| then |
| /// return -1. Otherwise, return 0 if the file is missing, or a strictly |
| /// positive value if it exists. |
| TimeStamp Stat(const std::string& path, std::string* err) const; |
| |
| /// Synchronize the cache state with recent filesystem events. |
| /// Call this before one or more Stat() calls. |
| void Sync(); |
| |
| /// Remove all entries from the cache. |
| void Flush(); |
| |
| private: |
| class Impl; |
| std::unique_ptr<Impl> impl_; |
| }; |
| |
| #endif // NINJA_STAT_CACHE_H_ |