4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
15 #include <boost/utility.hpp>
17 #include <sys/types.h>
30 /** Use objects of this class to get information about files.
32 * Users must make sure to check fi.isOK() before any operations
33 * requiring the file to exist such as fi.isDir()
35 class FileInfo : boost::noncopyable {
40 /** Get information about file.
41 If link is true, the information is about the link itself, not
42 the file that is obtained by tracing the links. */
43 explicit FileInfo(std::string const & path, bool link = false);
46 explicit FileInfo(int fildes);
49 FileInfo & newFile(std::string const & path, bool link = false);
51 /// Query a new file descriptor
52 FileInfo & newFile(int fildes);
54 /// Returns a character describing file type (ls -F)
55 char typeIndicator() const;
57 /// File protection mode
58 mode_t getMode() const;
60 /// Constructs standard mode string (ls style)
61 std::string modeString() const;
64 time_t getModificationTime() const;
67 time_t getAccessTime() const;
70 time_t getStatusChangeTime() const;
72 /// Total file size in bytes
73 off_t getSize() const;
81 /// Is the file information correct? Did the query succeed?
86 /// test for read permission
88 /// test for write permission
90 /// test for execute (search) permission
92 /// test for existence of file
95 /// Test whether the current user has a given set of permissions
96 bool access(int p) const;
97 /// Is the file writable for the current user?
98 bool writable() const { return access(FileInfo::wperm); }
99 /// Is the file readable for the current user?
100 bool readable() const { return access(FileInfo::rperm); }
101 /// Is the file executable for the current user?
102 bool executable() const { return access(FileInfo::xperm); }
103 /// Does the file exist?
104 bool exist() const { return access(FileInfo::eperm); }
108 bool isRegular() const;
114 bool isBlock() const;
118 bool isSocket() const;
120 int getError() const;
142 } // namespace support