// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-1999 The LyX Team.
+/**
+ * \file FileInfo.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ======================================================*/
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
#ifndef FILE_INFO_H
#define FILE_INFO_H
-#include <ctime>
+#include <boost/utility.hpp>
-#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <unistd.h>
+
+#include <ctime>
+#include <string>
-#include "LString.h"
-/** Use objects of this class to get information about files. */
-class FileInfo {
+namespace lyx {
+namespace support {
+
+/** Use objects of this class to get information about files.
+ *
+ * Users must make sure to check fi.isOK() before any operations
+ * requiring the file to exist such as fi.isDir()
+ */
+class FileInfo : boost::noncopyable {
public:
///
FileInfo();
/** Get information about file.
- If link is true, the information is about the link itself, not
- the file that is obtained by tracing the links. */
- FileInfo(string const & path, bool link = false);
+ If link is true, the information is about the link itself, not
+ the file that is obtained by tracing the links. */
+ explicit FileInfo(std::string const & path, bool link = false);
- ///
- FileInfo(int fildes);
+ /// File descriptor
+ explicit FileInfo(int fildes);
- ///
- ~FileInfo();
+ /// Query a new file
+ FileInfo & newFile(std::string const & path, bool link = false);
- ///
- FileInfo& newFile(string const & path, bool link = false);
+ /// Query a new file descriptor
+ FileInfo & newFile(int fildes);
- ///
- FileInfo& newFile(int fildes);
-
- /// returns a character describing file type (ls -F)
- char const * typeIndicator() const;
+ /// Returns a character describing file type (ls -F)
+ char typeIndicator() const;
- ///
+ /// File protection mode
mode_t getMode() const;
- ///
- long getBlockSize() const;
-
- /// constructs standard mode string (ls style)
- void modeString(char * szString) const;
-
- /// returns a letter describing a file type (ls style)
- char typeLetter() const;
-
- /// builds 'rwx' string describing file access rights
- void flagRWX(unsigned short i, char * szString) const;
-
- /// updates mode string to match suid/sgid/sticky bits
- void setSticky(char * szString) const;
+ /// Constructs standard mode string (ls style)
+ std::string modeString() const;
///
time_t getModificationTime() const;
///
time_t getStatusChangeTime() const;
- ///
+ /// Total file size in bytes
off_t getSize() const;
- ///
- nlink_t getNumberOfLinks() const;
-
- ///
+ /// User ID of owner
uid_t getUid() const;
- ///
+
+ /// Group ID of owner
gid_t getGid() const;
- ///
+
+ /// Is the file information correct? Did the query succeed?
bool isOK() const;
- ///
+
+ /// Permission flags
enum perm_test {
- rperm = R_OK, // test for read permission
- wperm = W_OK, // test for write permission
- xperm = X_OK, // test for execute (search) permission
- eperm = F_OK // test for existence of file
+ /// test for read permission
+ rperm = R_OK,
+ /// test for write permission
+ wperm = W_OK,
+ /// test for execute (search) permission
+ xperm = X_OK,
+ /// test for existence of file
+ eperm = F_OK
};
- ///
- bool access(int p);
- ///
- bool writable() { return access(FileInfo::wperm); }
- ///
- bool readable() { return access(FileInfo::rperm); }
- ///
- bool executable() { return access(FileInfo::xperm); }
- ///
- bool exist() { return access(FileInfo::eperm); }
+ /// Test whether the current user has a given set of permissions
+ bool access(int p) const;
+ /// Is the file writable for the current user?
+ bool writable() const { return access(FileInfo::wperm); }
+ /// Is the file readable for the current user?
+ bool readable() const { return access(FileInfo::rperm); }
+ /// Is the file executable for the current user?
+ bool executable() const { return access(FileInfo::xperm); }
+ /// Does the file exist?
+ bool exist() const { return access(FileInfo::eperm); }
///
bool isLink() const;
///
///
int getError() const;
///
- enum {
+ enum Err {
///
NoErr = -1
};
void init();
///
void dostat(bool);
+
///
- struct stat * buf;
+ struct stat buf_;
///
- int status;
+ int status_;
///
- int err;
+ int err_;
///
- string fname;
+ std::string fname_;
};
-#endif
+} // namespace support
+} // namespace lyx
+#endif