00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MORE_FILESYS_H
00032 #define MORE_FILESYS_H
00033
00034 #include <string>
00035 #include <list>
00036 #include <stdexcept>
00037
00038
00039 namespace more {
00040 namespace io {
00041
00042
00043 bool rename_node(std::string const& oldpath, std::string const& newpath);
00044
00045
00046 bool remove_node(std::string const& path);
00047
00048
00049
00050 bool remove_node_rec(std::string const& path);
00051
00052
00053 void remove_node_at_exit(std::string const& path);
00054
00055
00056 void remove_node_rec_at_exit(std::string const& path);
00057
00058
00059
00060 bool copy_node(std::string const& srcpath, std::string const& dstpath);
00061
00062
00063
00064 bool copy_node_rec(std::string const& srcpath, std::string const& dstpath);
00065
00066
00067 bool create_dir(std::string path);
00068
00069
00070
00071 bool create_dir_rec(std::string path);
00072
00073
00074
00075
00076 bool grep_string(std::string const& path, std::string const& str);
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 bool reserve_tmp_file(std::string& name, bool remove_p = true);
00087
00088
00089
00090
00091 struct tmp_file_reservation
00092 {
00093
00094 explicit tmp_file_reservation(std::string const& name)
00095 : m_name(name)
00096 {
00097 if (!reserve_tmp_file(m_name, false))
00098 m_name.clear();
00099 }
00100
00101
00102 ~tmp_file_reservation()
00103 {
00104 if (!m_name.empty())
00105 remove_node(m_name);
00106 }
00107
00108
00109
00110 std::string const& name()
00111 {
00112 if (m_name.empty())
00113 throw std::runtime_error("more::tmp_file_reservation::name: "
00114 "Could not reserve a tmp file.");
00115 return m_name;
00116 }
00117
00118
00119 bool is_reserved() const { return !m_name.empty(); }
00120
00121 private:
00122 std::string m_name;
00123 };
00124
00125
00126
00127
00128
00129
00130 bool create_tmp_dir(std::string& name);
00131
00132
00133
00134
00135
00136
00137
00138 struct file_status
00139 {
00140 static const int readable_flag = 4;
00141 static const int writable_flag = 2;
00142 static const int executable_flag = 1;
00143
00144 file_status(std::string);
00145 ~file_status();
00146
00147 bool good() const { return m_err == 0; }
00148 bool bad() const { return m_err != 0; }
00149
00150 int user_permissions() const;
00151 int permissions() const;
00152 unsigned int uid() const;
00153 unsigned int gid() const;
00154
00155 bool exists() const { return good(); }
00156 bool is_readable() const { return user_permissions() & readable_flag; }
00157 bool is_writable() const { return user_permissions() & writable_flag; }
00158 bool is_executable() const {return user_permissions()&executable_flag;}
00159
00160 bool is_regular_file() const;
00161 bool is_directory() const;
00162 bool is_symbolic_link() const;
00163
00164 double atime() const;
00165 double mtime() const;
00166
00167 private:
00168 void* m_stat;
00169 int m_err;
00170 };
00171
00172
00173
00174 struct file_glob_list
00175 {
00176
00177 typedef char const* const* iterator;
00178
00179 typedef char const* const* const_iterator;
00180
00181 file_glob_list(std::string patt);
00182 ~file_glob_list();
00183
00184
00185
00186 bool good() const { return m_data; }
00187
00188 const_iterator begin() const;
00189 const_iterator end() const;
00190
00191 private:
00192 void* m_data;
00193 };
00194
00195 typedef std::list<std::string> list_of_string;
00196 typedef list_of_string::iterator list_of_string_iterator;
00197 typedef list_of_string::const_iterator const_list_of_string_iterator;
00198
00199
00200
00201
00202 bool is_file_name_directory(std::string fname);
00203 bool is_file_name_non_directory(std::string fname);
00204 std::string file_name_as_directory(std::string fname);
00205 std::string directory_as_file_name(std::string fname);
00206 bool is_file_name_absolute(std::string fname);
00207 std::string file_name_directory(std::string fname);
00208 std::string file_name_nondirectory(std::string fname);
00209 std::pair<std::string, std::string>
00210 split_file_name(std::string fname);
00211 std::string path_list_to_file_name(const_list_of_string_iterator first,
00212 const_list_of_string_iterator past_end,
00213 std::string dir = ".");
00214 std::string file_name_extension(std::string fname);
00215 std::string file_name_sans_extension(std::string fname);
00216 std::string replace_extension(std::string fname, std::string ext);
00217 std::string resolve_file_name(std::string fname, std::string dir = ".");
00218 std::string absolute_file_name(std::string fname, std::string dir = ".");
00219 std::string relative_file_name(std::string fpath, std::string dir);
00220 std::string current_directory();
00221 std::string home_dir();
00222 std::string home_file(std::string fname);
00223
00224 }}
00225
00226 #endif