1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-15 10:54:16 +00:00
|
|
|
* ====================================================== */
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
#ifndef FILE_INFO_H
|
|
|
|
#define FILE_INFO_H
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <ctime>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2000-12-29 12:48:02 +00:00
|
|
|
#include <unistd.h>
|
2000-11-04 10:00:12 +00:00
|
|
|
#include <boost/utility.hpp>
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LString.h"
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
/** Use objects of this class to get information about files.
|
2002-01-07 10:17:44 +00:00
|
|
|
*
|
|
|
|
* Users must make sure to check fi.isOK() before any operations
|
|
|
|
* requiring the file to exist such as fi.isDir()
|
2000-08-07 20:58:24 +00:00
|
|
|
*/
|
2001-04-17 14:22:53 +00:00
|
|
|
class FileInfo : boost::noncopyable {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
///
|
|
|
|
FileInfo();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/** Get information about file.
|
1999-11-09 22:20:24 +00:00
|
|
|
If link is true, the information is about the link itself, not
|
|
|
|
the file that is obtained by tracing the links. */
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-10-02 16:21:10 +00:00
|
|
|
FileInfo(string const & path, bool link = false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// File descriptor
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo(int fildes);
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Query a new file
|
1999-11-09 22:20:24 +00:00
|
|
|
FileInfo & newFile(string const & path, bool link = false);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Query a new file descriptor
|
2002-03-21 17:09:55 +00:00
|
|
|
FileInfo & newFile(int fildes);
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Returns a character describing file type (ls -F)
|
1999-10-02 16:21:10 +00:00
|
|
|
char const * typeIndicator() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// File protection mode
|
1999-09-27 18:44:28 +00:00
|
|
|
mode_t getMode() const;
|
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Constructs standard mode string (ls style)
|
2002-07-16 10:05:52 +00:00
|
|
|
void modeString(char * str) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// returns a letter describing a file type (ls style)
|
|
|
|
char typeLetter() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
time_t getModificationTime() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
time_t getAccessTime() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
time_t getStatusChangeTime() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Total file size in bytes
|
1999-09-27 18:44:28 +00:00
|
|
|
off_t getSize() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Number of hard links
|
1999-09-27 18:44:28 +00:00
|
|
|
nlink_t getNumberOfLinks() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// User ID of owner
|
1999-09-27 18:44:28 +00:00
|
|
|
uid_t getUid() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Group ID of owner
|
1999-09-27 18:44:28 +00:00
|
|
|
gid_t getGid() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file information correct? Did the query succeed?
|
1999-09-27 18:44:28 +00:00
|
|
|
bool isOK() const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Permission flags
|
1999-09-27 18:44:28 +00:00
|
|
|
enum perm_test {
|
2000-08-07 20:58:24 +00:00
|
|
|
/// 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
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Test whether the current user has a given set of permissions
|
2000-11-04 10:00:12 +00:00
|
|
|
bool access(int p) const;
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file writable for the current user?
|
2000-11-04 10:00:12 +00:00
|
|
|
bool writable() const { return access(FileInfo::wperm); }
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file readable for the current user?
|
2000-11-04 10:00:12 +00:00
|
|
|
bool readable() const { return access(FileInfo::rperm); }
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Is the file executable for the current user?
|
2000-11-04 10:00:12 +00:00
|
|
|
bool executable() const { return access(FileInfo::xperm); }
|
1999-10-12 21:37:10 +00:00
|
|
|
/// Does the file exist?
|
2000-11-04 10:00:12 +00:00
|
|
|
bool exist() const { return access(FileInfo::eperm); }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
bool isLink() const;
|
|
|
|
///
|
|
|
|
bool isRegular() const;
|
|
|
|
///
|
|
|
|
bool isDir() const;
|
|
|
|
///
|
|
|
|
bool isChar() const;
|
|
|
|
///
|
|
|
|
bool isBlock() const;
|
|
|
|
///
|
|
|
|
bool isFifo() const;
|
|
|
|
///
|
|
|
|
bool isSocket() const;
|
|
|
|
///
|
|
|
|
int getError() const;
|
|
|
|
///
|
2000-08-07 20:58:24 +00:00
|
|
|
enum Err {
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
NoErr = -1
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
void init();
|
|
|
|
///
|
|
|
|
void dostat(bool);
|
2002-07-16 10:05:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2002-07-16 10:05:52 +00:00
|
|
|
struct stat buf_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2002-07-16 10:05:52 +00:00
|
|
|
int status_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2002-07-16 10:05:52 +00:00
|
|
|
int err_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2002-07-16 10:05:52 +00:00
|
|
|
string fname_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|