diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2022-12-23 22:57:27 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2023-01-09 11:33:08 +0300 |
commit | 31b74a064317186d7e891207de803b9d6dfb2642 (patch) | |
tree | 5c38a5728d72168a8c9218befaa2a6e42674ff6e /libbutl/filesystem.hxx | |
parent | bded624bacbc284e523e44d73572a4f60d817b03 (diff) |
Add mtime() and atime() to dir_entry
Diffstat (limited to 'libbutl/filesystem.hxx')
-rw-r--r-- | libbutl/filesystem.hxx | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/libbutl/filesystem.hxx b/libbutl/filesystem.hxx index 71b3ebd..ea5597d 100644 --- a/libbutl/filesystem.hxx +++ b/libbutl/filesystem.hxx @@ -664,6 +664,33 @@ namespace butl entry_type ltype () const; + // Modification and access times of the filesystem entry if it is not a + // symlink and of the symlink target otherwise. + // + // These are provided as an optimization if they can be obtained as a + // byproduct of work that is already being done anyway (iteration itself, + // calls to [l]type(), etc). If (not yet) available, timestamp_unknown is + // returned. + // + // Specifically: + // + // - On Windows mtime is always set by dir_iterator for entries other than + // reparse points. + // + // - On all platforms mtime and atime are always set for symlink targets + // by dir_iterator in the {detect,ignore}_dangling modes. + // + // - On all platforms mtime and atime can potentially be set by [l]type() + // if the stat() call is required to retrieve the type information (the + // native directory entry iterating API doesn't provide it, the type of + // the symlink target is queried, etc). + // + timestamp + mtime () const {return mtime_;} + + timestamp + atime () const {return atime_;} + // Entry path (excluding the base). To get the full path, do // base () / path (). // @@ -674,8 +701,17 @@ namespace butl base () const {return b_;} dir_entry () = default; - dir_entry (entry_type t, path_type p, dir_path b) - : t_ (t), p_ (std::move (p)), b_ (std::move (b)) {} + + dir_entry (entry_type t, + path_type p, + dir_path b, + timestamp mt = timestamp_unknown, + timestamp at = timestamp_unknown) + : t_ (t), + mtime_ (mt), + atime_ (at), + p_ (std::move (p)), + b_ (std::move (b)) {} private: entry_type @@ -689,6 +725,9 @@ namespace butl mutable optional<entry_type> t_; // Entry type. mutable optional<entry_type> lt_; // Symlink target type. + mutable timestamp mtime_ = timestamp_unknown; + mutable timestamp atime_ = timestamp_unknown; + path_type p_; dir_path b_; }; |