File.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_File_hxx
00024 #define __ccxx_File_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/FileName.h++>
00028 #include <commonc++/Permissions.h++>
00029 #include <commonc++/Stream.h++>
00030 #include <commonc++/String.h++>
00031
00032 namespace ccxx {
00033
00034 enum FileType { TypeFile, TypeDir, TypeSymLink, TypePipe, TypeDevice,
00035 TypeOther, TypeUnknown };
00036
00037 enum FileOpenMode { FileOpenElseCreate, FileOpen, FileCreate, FileTruncate,
00038 FileTruncateElseCreate };
00039
00045 struct COMMONCPP_API FileAttributes
00046 {
00049 FileAttributes()
00050 : type(TypeUnknown),
00051 created(INT64_CONST(0)),
00052 modified(INT64_CONST(0)),
00053 accessed(INT64_CONST(0)),
00054 size(UINT64_CONST(0))
00055 { }
00056
00058 FileType type;
00060 time_ms_t created;
00062 time_ms_t modified;
00064 time_ms_t accessed;
00066 uint64_t size;
00068 Permissions permissions;
00069
00071 inline bool isDirectory() const throw()
00072 { return(type == TypeDir); }
00073
00075 inline bool isFile() const throw()
00076 { return(type == TypeFile); }
00077 };
00078
00079 enum LockType { LockRead, LockWrite };
00080
00087 class COMMONCPP_API File : public Stream
00088 {
00089 public:
00090
00095 File(const String &path);
00096
00098 virtual ~File() throw();
00099
00107 void open(IOMode mode = IOReadWrite,
00108 FileOpenMode openMode = FileOpenElseCreate,
00109 const Permissions &perm = Permissions::USER_READ_WRITE)
00110 throw(IOException);
00111
00113 bool exists() const throw();
00114
00116 bool isDirectory() const throw();
00117
00119 bool isFile() const throw();
00120
00122 bool isPipe() const throw();
00123
00129 bool isSymLink() const throw();
00130
00136 bool touch() throw();
00137
00143 bool remove() throw();
00144
00150 bool setPermissions(const Permissions &perm) throw();
00151
00159 bool getPermissions(Permissions &perm) throw();
00160
00172 bool lockRange(uint64_t start, uint64_t length, LockType type,
00173 bool wait = true) throw();
00174
00183 bool unlockRange(uint64_t start, uint64_t length) throw();
00184
00195 void truncate(uint64_t size = 0) throw(IOException);
00196
00198 inline String getPath() const
00199 { return(_name); }
00200
00206 int64_t getSize() throw(IOException);
00207
00217 static bool makeDirectory(
00218 const String &path, bool createAll = false,
00219 const Permissions &perm = Permissions::defaultDirPerms) throw();
00220
00227 static bool remove(const String &path) throw();
00228
00236 static bool removeDirectory(const String &path) throw();
00237
00245 static bool removeDirectoryTree(const String &path);
00246
00252 static bool exists(const String &path) throw();
00253
00260 static bool isDirectory(const String &path) throw();
00261
00268 static bool isFile(const String &path) throw();
00269
00276 static bool isPipe(const String &path) throw();
00277
00285 static bool isSymLink(const String &path) throw();
00286
00295 static bool readSymLink(String &path) throw();
00296
00304 static bool resolveSymLink(String &path) throw();
00305
00315 static bool createLink(const String &oldPath, const String &newPath,
00316 bool hardLink = false) throw();
00317
00324 static bool setPermissions(const String &path, const Permissions &perm)
00325 throw();
00326
00334 static bool getPermissions(const String &path, Permissions &perm)
00335 throw();
00336
00344 static bool getAttributes(const String &path, FileAttributes &attrs)
00345 throw();
00346
00353 static int64_t getSize(const String &path) throw();
00354
00361 static bool rename(const String &oldName, const String &newName) throw();
00362
00369 static bool copy(const String &oldFile, const String &newFile) throw();
00370
00378 static bool move(const String &oldFile, const String &newFile) throw();
00379
00386 static bool touch(const String &path) throw();
00387
00397 static void getFileSystemRoots(StringVec &roots, bool localOnly = true)
00398 throw();
00399
00406 static void setCreationMask(const Permissions &perm) throw();
00407
00417 static uint64_t getDiskFreeSpace(const String &path) throw();
00418
00428 static size_t getDiskBlockSize(const String &path) throw();
00429
00438 static int64_t roundSizeToBlockSize(const int64_t &fileSize,
00439 size_t blockSize);
00440
00446 static String removeTrailingSeparators(const String &path) throw();
00447
00449 static const char separator;
00450
00455 static const char validSeparators[];
00456
00460 static bool isValidSeparator(char c) throw();
00461
00463 static const char separatorString[];
00464
00466 static const char *eol;
00467
00468 protected:
00469
00470 String _name;
00471
00472 private:
00473
00474 CCXX_COPY_DECLS(File);
00475 };
00476
00477 };
00478
00479 #endif // __ccxx_File_hxx
00480
00481