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
17 #include <sys/types.h>
20 #include <boost/utility.hpp>
23 /** Use objects of this class to get information about files.
25 * Users must make sure to check fi.isOK() before any operations
26 * requiring the file to exist such as fi.isDir()
28 class FileInfo : boost::noncopyable {
33 /** Get information about file.
34 If link is true, the information is about the link itself, not
35 the file that is obtained by tracing the links. */
36 explicit FileInfo(string const & path, bool link = false);
39 explicit FileInfo(int fildes);
42 FileInfo & newFile(string const & path, bool link = false);
44 /// Query a new file descriptor
45 FileInfo & newFile(int fildes);
47 /// Returns a character describing file type (ls -F)
48 char typeIndicator() const;
50 /// File protection mode
51 mode_t getMode() const;
53 /// Constructs standard mode string (ls style)
54 string modeString() const;
57 time_t getModificationTime() const;
60 time_t getAccessTime() const;
63 time_t getStatusChangeTime() const;
65 /// Total file size in bytes
66 off_t getSize() const;
68 /// Number of hard links
69 nlink_t getNumberOfLinks() const;
77 /// Is the file information correct? Did the query succeed?
82 /// test for read permission
84 /// test for write permission
86 /// test for execute (search) permission
88 /// test for existence of file
91 /// Test whether the current user has a given set of permissions
92 bool access(int p) const;
93 /// Is the file writable for the current user?
94 bool writable() const { return access(FileInfo::wperm); }
95 /// Is the file readable for the current user?
96 bool readable() const { return access(FileInfo::rperm); }
97 /// Is the file executable for the current user?
98 bool executable() const { return access(FileInfo::xperm); }
99 /// Does the file exist?
100 bool exist() const { return access(FileInfo::eperm); }
104 bool isRegular() const;
110 bool isBlock() const;
114 bool isSocket() const;
116 int getError() const;