00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PALUDIS_GUARD_PALUDIS_FS_ENTRY_HH
00022 #define PALUDIS_GUARD_PALUDIS_FS_ENTRY_HH 1
00023
00024 #include <paludis/util/fs_entry-fwd.hh>
00025 #include <paludis/util/exception.hh>
00026 #include <paludis/util/operators.hh>
00027 #include <paludis/util/private_implementation_pattern.hh>
00028 #include <string>
00029 #include <tr1/memory>
00030 #include <iosfwd>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <ctime>
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 struct stat;
00046 struct utimbuf;
00047
00048 namespace paludis
00049 {
00050
00051
00052
00053
00054
00055
00056
00057 class PALUDIS_VISIBLE FSError :
00058 public Exception
00059 {
00060 public:
00061
00062
00063
00064 FSError(const std::string & message) throw ();
00065
00066
00067 };
00068
00069
00070
00071
00072
00073
00074 class PALUDIS_VISIBLE FSEntry :
00075 public relational_operators::HasRelationalOperators,
00076 public arithmetic_operators::HasArithmeticOperators,
00077 private PrivateImplementationPattern<FSEntry>
00078 {
00079 friend std::ostream & operator<< (std::ostream & s, const FSEntry & f);
00080 friend class DirIterator;
00081
00082 private:
00083 void _normalise();
00084
00085
00086
00087
00088
00089
00090 void _stat() const;
00091
00092 FSEntry(const std::string & path, unsigned char d_type);
00093
00094 public:
00095
00096
00097
00098 FSEntry(const std::string & path);
00099
00100 FSEntry(const FSEntry & other);
00101
00102 ~FSEntry();
00103
00104 const FSEntry & operator= (const FSEntry & other);
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 const FSEntry & operator/= (const FSEntry & rhs);
00115
00116
00117
00118
00119 const FSEntry & operator/= (const std::string & rhs)
00120 {
00121 return operator/= (FSEntry(rhs));
00122 }
00123
00124
00125
00126
00127 FSEntry operator/ (const std::string & rhs) const
00128 PALUDIS_ATTRIBUTE((warn_unused_result));
00129
00130
00131
00132
00133
00134
00135
00136 bool operator< (const FSEntry &) const;
00137 bool operator== (const FSEntry &) const;
00138
00139
00140
00141
00142
00143
00144 std::string basename() const
00145 PALUDIS_ATTRIBUTE((warn_unused_result));
00146
00147
00148
00149
00150 FSEntry strip_leading(const FSEntry & prefix) const;
00151
00152
00153
00154
00155 FSEntry dirname() const
00156 PALUDIS_ATTRIBUTE((warn_unused_result));
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 bool exists() const
00168 PALUDIS_ATTRIBUTE((warn_unused_result));
00169
00170
00171
00172
00173
00174 bool is_directory() const
00175 PALUDIS_ATTRIBUTE((warn_unused_result));
00176
00177
00178
00179
00180
00181 bool is_directory_or_symlink_to_directory() const
00182 PALUDIS_ATTRIBUTE((warn_unused_result));
00183
00184
00185
00186
00187
00188 bool is_regular_file() const
00189 PALUDIS_ATTRIBUTE((warn_unused_result));
00190
00191
00192
00193
00194
00195 bool is_regular_file_or_symlink_to_regular_file() const
00196 PALUDIS_ATTRIBUTE((warn_unused_result));
00197
00198
00199
00200
00201
00202 bool is_symbolic_link() const
00203 PALUDIS_ATTRIBUTE((warn_unused_result));
00204
00205
00206
00207
00208 bool is_device() const
00209 PALUDIS_ATTRIBUTE((warn_unused_result));
00210
00211
00212
00213
00214 bool is_fifo() const
00215 PALUDIS_ATTRIBUTE((warn_unused_result));
00216
00217
00218
00219
00220
00221
00222 bool has_permission(const FSUserGroup & user_group, const FSPermission & fs_perm) const
00223 PALUDIS_ATTRIBUTE((warn_unused_result));
00224
00225
00226
00227
00228
00229
00230 mode_t permissions() const
00231 PALUDIS_ATTRIBUTE((warn_unused_result));
00232
00233
00234
00235
00236 FSEntry realpath() const
00237 PALUDIS_ATTRIBUTE((warn_unused_result));
00238
00239
00240
00241
00242
00243 FSEntry realpath_if_exists() const
00244 PALUDIS_ATTRIBUTE((warn_unused_result));
00245
00246
00247
00248
00249
00250
00251
00252 std::string readlink() const
00253 PALUDIS_ATTRIBUTE((warn_unused_result));
00254
00255
00256
00257
00258
00259 time_t ctime() const
00260 PALUDIS_ATTRIBUTE((warn_unused_result));
00261
00262
00263
00264
00265
00266 time_t mtime() const
00267 PALUDIS_ATTRIBUTE((warn_unused_result));
00268
00269
00270
00271
00272
00273
00274 off_t file_size() const
00275 PALUDIS_ATTRIBUTE((warn_unused_result));
00276
00277
00278
00279
00280
00281
00282 uid_t owner() const
00283 PALUDIS_ATTRIBUTE((warn_unused_result));
00284
00285
00286
00287
00288
00289
00290 gid_t group() const
00291 PALUDIS_ATTRIBUTE((warn_unused_result));
00292
00293
00294
00295
00296 static FSEntry cwd()
00297 PALUDIS_ATTRIBUTE((warn_unused_result));
00298
00299
00300
00301
00302 std::pair<dev_t, ino_t> lowlevel_id() const
00303 PALUDIS_ATTRIBUTE((warn_unused_result));
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 bool mkdir(const mode_t mode = 0755);
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 bool symlink(const std::string & target);
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 bool unlink();
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 bool rmdir();
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 bool utime(const struct ::utimbuf * buf = 0);
00364
00365
00366
00367
00368
00369
00370 void chown(const uid_t owner, const gid_t group = static_cast<gid_t>(-1));
00371
00372
00373
00374
00375
00376
00377 void lchown(const uid_t owner, const gid_t group = static_cast<gid_t>(-1));
00378
00379
00380
00381
00382
00383
00384 void chmod(const mode_t mode);
00385
00386
00387
00388
00389
00390
00391 void rename(const FSEntry & new_name);
00392
00393
00394 };
00395 }
00396
00397 #endif