12 #ifndef __UT_FileUtil__
13 #define __UT_FileUtil__
32 #define UT_FILEUTIL_PROMPT 1
35 #define UT_FILEUTIL_INCLUSIVE 2
55 static int64 getFileSize(
const char *
path);
59 static time_t getFileModTime(
const char *
path);
65 static time_t getRecursiveDirMaxModTime(
const char *
path);
69 static int getMaxFileDescriptors();
81 static int resolveSymbolicLinks(
const char *
path,
83 bool allow_dangling_link =
false);
88 static int copyFile(
const char *srcname,
const char *dstname,
89 std::ostream *error_os =
nullptr);
91 static int copyDir(
const char *srcname,
const char *dstname);
94 static int copyFileToStream(
const char *srcname, std::ostream &os);
97 static int moveFile(
const char *srcname,
const char *dstname);
99 static int removeFile(
const char *fname);
102 static int removeDir(
const char *dname,
103 UT_RemoveDepth
depth = IF_EMPTY);
113 static bool makeDir(
const char *
path, mode_t
mode=0777,
114 bool ignore_umask =
false);
122 static bool makeDirs(
const char *
path, mode_t
mode=0777,
123 bool ignore_umask =
false);
133 static bool lockFile(
int fd);
138 static bool unlockFile(
int fd);
148 static bool writeLockFile(
int fd);
158 static bool readLockFile(
int fd);
165 static void upDirectory(
char *
path,
int levels);
171 static int removeLinesFromFile(
const char *fname,
172 const char *prefix,
int readonly = 0);
180 int removeOverrideFiles(
const char *newbasepath,
181 const char *relpath,
const char *fname,
182 const char *english,
int flags,
183 const char *stripinfo = 0);
188 static bool readXMLElementFromFile(
const char * xml_file_path,
189 const char * element_name,
197 virtual int showPrompt(
const char *prompt);
217 lock(filename,
true);
225 lock(filename, exclusive);
245 myFile = SYSfopen(filename, exclusive ?
"rb+" :
"rb");
255 myFile = SYSfopen(filename,
"wb+");
259 myLockSucceeded =
false;
270 myLockSucceeded =
false;
287 return myLockSucceeded;
291 FILE *myFile =
nullptr;
292 bool myLockSucceeded =
false;
static bool unlockFile(int fd)
GT_API const UT_StringHolder filename
GLsizei const GLchar *const * path
void lock(const char *filename, bool exclusive)
**But if you need a result
bool isLocked() const
Return whether the file is actually locked.
UT_AutoFileLock(UT_EmptyFileLock)
Construct without lock. Use lock() with filename to acquire one.
#define SYS_NO_DISCARD_RESULT
FILE * getFile() const
Get the file pointer for this locked file.
GLint GLint GLsizei GLsizei GLsizei depth
static bool writeLockFile(int fd)
LeafData & operator=(const LeafData &)=delete
UT_AutoFileLock(const char *filename)
Open and lock a file for exclusive reading and writing.
static bool readLockFile(int fd)
UT_AutoFileLock(const char *filename, bool exclusive)