12 #ifndef __UT_FileUtil__
13 #define __UT_FileUtil__
33 #define UT_FILEUTIL_PROMPT 1
36 #define UT_FILEUTIL_INCLUSIVE 2
56 static int64 getFileSize(
const char *
path);
60 static time_t getFileModTime(
const char *
path);
70 static time_t getRecursiveDirMaxModTime(
const char *
path);
71 static time_t getRecursiveDirMaxModTime(
const char *
path,
const UT_FileStat &fstat);
75 static int getMaxFileDescriptors();
87 static int resolveSymbolicLinks(
const char *
path,
89 bool allow_dangling_link =
false);
94 static int copyFile(
const char *srcname,
const char *dstname,
95 std::ostream *error_os =
nullptr);
97 static int copyDir(
const char *srcname,
const char *dstname);
100 static int copyFileToStream(
const char *srcname, std::ostream &os);
103 static int moveFile(
const char *srcname,
const char *dstname);
105 static int removeFile(
const char *fname);
108 static int removeDir(
const char *dname,
109 UT_RemoveDepth
depth = IF_EMPTY);
119 static bool makeDir(
const char *
path, mode_t
mode=0777,
120 bool ignore_umask =
false);
128 static bool makeDirs(
const char *
path, mode_t
mode=0777,
129 bool ignore_umask =
false);
139 static bool lockFile(
int fd);
144 static bool unlockFile(
int fd);
154 static bool writeLockFile(
int fd);
164 static bool readLockFile(
int fd);
171 static void upDirectory(
char *
path,
int levels);
177 static int removeLinesFromFile(
const char *fname,
178 const char *prefix,
int readonly = 0);
186 int removeOverrideFiles(
const char *newbasepath,
187 const char *relpath,
const char *fname,
188 const char *english,
int flags,
189 const char *stripinfo = 0);
194 static bool readXMLElementFromFile(
const char * xml_file_path,
195 const char * element_name,
203 virtual int showPrompt(
const char *prompt);
223 lock(filename,
true);
231 lock(filename, exclusive);
251 myFile = SYSfopen(filename, exclusive ?
"rb+" :
"rb");
261 myFile = SYSfopen(filename,
"wb+");
265 myLockSucceeded =
false;
276 myLockSucceeded =
false;
293 return myLockSucceeded;
297 FILE *myFile =
nullptr;
298 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)