1 /***************************************************************************
2 * Copyright (C) 2004-2008 by Intra2net AG *
5 ***************************************************************************/
10 #include "userfunc.hpp"
15 * @brief helper class representing a file state.
17 * This basically wraps struct stat and provides some nicer access to the values.
23 Stat(const std::string& path, bool follow_links= true);
28 bool is_valid() const { return Valid; }
30 bool exists() const { return Valid; }
31 std::string path() const { return Path; }
33 dev_t device() const { return Device; }
34 ino_t inode() const { return Inode; }
35 mode_t mode() const { return Mode; }
36 nlink_t nlink() const { return NumLinks; }
37 uid_t uid() const { return Uid; }
38 gid_t gid() const { return Gid; }
39 dev_t rdev() const { return DeviceType; }
40 off_t size() const { return Size; }
41 time_t atime() const { return Atime; }
42 time_t mtime() const { return Mtime; }
43 time_t ctime() const { return Ctime; }
45 nlink_t num_hard_links() const { return NumLinks; }
46 dev_t device_type() const { return DeviceType; }
47 time_t last_modified_time() const { return Mtime; }
48 time_t created_time() const { return Ctime; }
51 ** unix style like type queries:
54 bool is_lnk() const { return IsLink; }
55 bool is_reg() const { return IsRegular; }
56 bool is_dir() const { return IsDirectory; }
57 bool is_chr() const { return IsCharacterDevice; }
58 bool is_blk() const { return IsBlockDevice; }
59 bool is_fifo() const { return IsFifo; }
60 bool is_sock() const { return IsSocket; }
63 ** readable style type queries:
66 bool is_link () const { return IsLink; }
67 bool is_regular() const { return IsRegular; }
68 bool is_regular_file() const { return IsRegular; }
69 bool is_directory() const { return IsDirectory; }
70 bool is_character_device() const {return IsCharacterDevice; }
71 bool is_block_device() const { return IsBlockDevice; }
72 bool is_socket() const { return IsSocket; }
74 bool is_device() const { return IsCharacterDevice or IsBlockDevice; }
78 ** "high level" queries
81 bool is_same_as(const Stat& rhs);
82 bool is_same_device_as(const Stat& rhs);
85 ** convenience methods
88 operator bool() const { return Valid; }
92 void stat(const std::string& path, bool follow_links= true);
115 bool IsDirectory : 1;
116 bool IsCharacterDevice : 1;
117 bool IsBlockDevice : 1;
123 ** misc tool functions
124 ** (basically wrappers around system functions)
127 bool path_exists(const std::string& path);
128 bool file_exists(const std::string& path);
129 long file_size (const std::string &name);
131 time_t file_mtime(const std::string& path);
133 bool get_dir(const std::string& path, std::vector< std::string >& result, bool include_dot_names= false );
134 std::vector< std::string > get_dir(const std::string& path, bool include_dot_names= false );
136 bool unlink(const std::string& path);
138 bool symlink(const std::string& target, const std::string& link_name, bool force= false);
140 std::string read_link(const std::string& path);
142 std::string read_file(const std::string& path);
144 bool write_file(const std::string& path, const std::string& data);
146 bool copy_file(const std::string& src, const std::string& dest);
148 std::string basename(const std::string& path);
150 std::string dirname(const std::string& path);
152 std::string normalize_path(const std::string& path);
154 bool chmod(const std::string& path, int mode);
155 bool chown(const std::string& path, const I2n::User& user, const I2n::Group& group= I2n::Group());
157 bool recursive_delete(const std::string &path, std::string *error=NULL);