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;
73 /// Number of hard links
74 nlink_t getNumberOfLinks() const;
82 /// Is the file information correct? Did the query succeed?
87 /// test for read permission
89 /// test for write permission
91 /// test for execute (search) permission
93 /// test for existence of file
96 /// Test whether the current user has a given set of permissions
97 bool access(int p) const;
98 /// Is the file writable for the current user?
99 bool writable() const { return access(FileInfo::wperm); }
100 /// Is the file readable for the current user?
101 bool readable() const { return access(FileInfo::rperm); }
102 /// Is the file executable for the current user?
103 bool executable() const { return access(FileInfo::xperm); }
104 /// Does the file exist?
105 bool exist() const { return access(FileInfo::eperm); }
109 bool isRegular() const;
115 bool isBlock() const;
119 bool isSocket() const;
121 int getError() const;
143 } // namespace support