6 #include <msp/core/mspcore_api.h>
7 #include <msp/time/timestamp.h>
21 typedef uint64_t FileSize;
24 Holds file information.
26 class MSPCORE_API Stat
38 FileType type = UNKNOWN;
40 FileSize alloc_size = 0;
41 Time::TimeStamp mtime;
42 mutable OwnerInfo owner_info;
43 Private *priv = nullptr;
48 Stat &operator=(const Stat &);
51 FileType get_type() const { return type; }
52 bool is_regular() const { return type==REGULAR; }
53 bool is_directory() const { return type==DIRECTORY; }
54 bool is_symlink() const { return type==SYMLINK; }
55 FileSize get_size() const { return size; }
56 FileSize get_alloc_size() const { return alloc_size; }
57 const Time::TimeStamp &get_modify_time() const { return mtime; }
58 const std::string &get_owner() const;
59 const std::string &get_group() const;
61 operator bool() const { return exists; }
63 /// Returns a Stat object describing a file.
64 static Stat stat(const Path &);
65 static Stat lstat(const Path &);
68 /// Convenience wrapper for Stat::stat
69 inline Stat stat(const Path &path)
70 { return Stat::stat(path); }
72 /// Convenience wrapper for Stat::lstat
73 inline Stat lstat(const Path &path)
74 { return Stat::lstat(path); }
76 /// Tests for existence of a file
77 MSPCORE_API bool exists(const Path &path);
79 /// Tests whether a path refers to an existing regular file
80 inline bool is_reg(const Path &path)
81 { return stat(path).is_regular(); }
83 /// Tests whether a path refers to an existing directory
84 inline bool is_dir(const Path &path)
85 { return stat(path).is_directory(); }
87 /// Tests whether a path refers to a symbolic link
88 inline bool is_link(const Path &path)
89 { return lstat(path).is_symlink(); }