aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util/file_platform.h
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-19 14:56:30 +0000
committerGravatar Vladimir Moskva <vladmos@google.com>2017-01-19 18:00:35 +0000
commitce1b3e1324039dd7e1a3c1d219ad44daa3012eda (patch)
tree74d2711664badab11607380feb59ce693528d273 /src/main/cpp/util/file_platform.h
parent513d6451be3ee277baa127128f20eddab0c2be75 (diff)
Bazel client: abstract away mtime handling
Create an IFileMtime class and platform-specific implementations to deal with mtime handling. Since epochs and time granularity vary from platform to platform, and we only care about setting a file's/directory's mtime to the current time or to a future time plus querying whether something is in the future, we can easily create an interface for these operations and that's exactly what IFileMtime is. Implement PosixFileMtime and WindowsFileMtime. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144956966 MOS_MIGRATED_REVID=144956966
Diffstat (limited to 'src/main/cpp/util/file_platform.h')
-rw-r--r--src/main/cpp/util/file_platform.h33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h
index 6c2e20500c..600820ba0c 100644
--- a/src/main/cpp/util/file_platform.h
+++ b/src/main/cpp/util/file_platform.h
@@ -26,6 +26,30 @@ class IPipe;
IPipe* CreatePipe();
+// Class to query/manipulate the last modification time (mtime) of files.
+class IFileMtime {
+ public:
+ virtual ~IFileMtime() {}
+
+ // Queries the mtime of `path` to see whether it's in the distant future.
+ // Returns true if querying succeeded and stores the result in `result`.
+ // Returns false if querying failed.
+ virtual bool GetIfInDistantFuture(const std::string &path, bool *result) = 0;
+
+ // Sets the mtime of file under `path` to the current time.
+ // Returns true if the mtime was changed successfully.
+ virtual bool SetToNow(const std::string &path) = 0;
+
+ // Sets the mtime of file under `path` to the distant future.
+ // "Distant future" should be on the order of some years into the future, like
+ // a decade.
+ // Returns true if the mtime was changed successfully.
+ virtual bool SetToDistantFuture(const std::string &path) = 0;
+};
+
+// Creates a platform-specific implementation of `IFileMtime`.
+IFileMtime *CreateFileMtime();
+
// Split a path to dirname and basename parts.
std::pair<std::string, std::string> SplitPath(const std::string &path);
@@ -80,15 +104,6 @@ bool IsAbsolute(const std::string &path);
// pdie() if syncing fails.
void SyncFile(const std::string& path);
-// Returns the last modification time of `path` in milliseconds since the Epoch.
-// Returns -1 upon failure.
-time_t GetMtimeMillisec(const std::string& path);
-
-// Sets the last modification time of `path` to the given value.
-// `mtime` must be milliseconds since the Epoch.
-// Returns true upon success.
-bool SetMtimeMillisec(const std::string& path, time_t mtime);
-
// mkdir -p path. All newly created directories use the given mode.
// `mode` should be an octal permission mask, e.g. 0755.
// Returns false on failure, sets errno.