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>
28 /** Use objects of this class to get information about files.
30 * Users must make sure to check fi.isOK() before any operations
31 * requiring the file to exist such as fi.isDir()
33 class FileInfo : boost::noncopyable {
38 /** Get information about file.
39 If link is true, the information is about the link itself, not
40 the file that is obtained by tracing the links. */
41 explicit FileInfo(std::string const & path, bool link = false);
44 explicit FileInfo(int fildes);
47 FileInfo & newFile(std::string const & path, bool link = false);
49 /// Query a new file descriptor
50 FileInfo & newFile(int fildes);
52 /// Returns a character describing file type (ls -F)
53 char typeIndicator() const;
55 /// File protection mode
56 mode_t getMode() const;
58 /// Constructs standard mode string (ls style)
59 std::string modeString() const;
62 time_t getModificationTime() const;
65 time_t getAccessTime() const;
68 time_t getStatusChangeTime() const;
70 /// Total file size in bytes
71 off_t getSize() const;
79 /// Is the file information correct? Did the query succeed?
84 /// test for read permission
86 /// test for write permission
88 /// test for execute (search) permission
90 /// test for existence of file
93 /// Test whether the current user has a given set of permissions
94 bool access(int p) const;
95 /// Is the file writable for the current user?
96 bool writable() const { return access(FileInfo::wperm); }
97 /// Is the file readable for the current user?
98 bool readable() const { return access(FileInfo::rperm); }
99 /// Is the file executable for the current user?
100 bool executable() const { return access(FileInfo::xperm); }
101 /// Does the file exist?
102 bool exist() const { return access(FileInfo::eperm); }
106 bool isRegular() const;
112 bool isBlock() const;
116 bool isSocket() const;
118 int getError() const;
140 } // namespace support