HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_FileUtil Class Reference

#include <UT_FileUtil.h>

Public Types

enum  UT_RemoveDepth { IF_EMPTY, ALL_CONTENTS }
 

Public Member Functions

 UT_FileUtil ()
 
virtual ~UT_FileUtil ()
 
 UT_FileUtil (const UT_FileUtil &)=delete
 
UT_FileUtiloperator= (const UT_FileUtil &)=delete
 
int removeOverrideFiles (const char *newbasepath, const char *relpath, const char *fname, const char *english, int flags, const char *stripinfo=0)
 
virtual void showError (const char *error, int severity=2)
 
virtual int showPrompt (const char *prompt)
 

Static Public Member Functions

static int64 getFileSize (const char *path)
 
static time_t getFileModTime (const char *path)
 
static time_t getRecursiveDirMaxModTime (const char *path)
 
static int getMaxFileDescriptors ()
 
static bool getShortPathName (UT_WorkBuffer &result, const char *path)
 
static int resolveSymbolicLinks (const char *path, UT_WorkBuffer &contents, bool allow_dangling_link=false)
 
static int copyFile (const char *srcname, const char *dstname, std::ostream *error_os=nullptr)
 
static int copyDir (const char *srcname, const char *dstname)
 
static int copyFileToStream (const char *srcname, std::ostream &os)
 
static int moveFile (const char *srcname, const char *dstname)
 
static int removeFile (const char *fname)
 
static int removeDir (const char *dname, UT_RemoveDepth depth=IF_EMPTY)
 
static bool makeDir (const char *path, mode_t mode=0777, bool ignore_umask=false)
 
static bool makeDirs (const char *path, mode_t mode=0777, bool ignore_umask=false)
 
static bool lockFile (int fd)
 
static bool unlockFile (int fd)
 
static bool writeLockFile (int fd)
 
static bool readLockFile (int fd)
 
static void upDirectory (char *path, int levels)
 
static int removeLinesFromFile (const char *fname, const char *prefix, int readonly=0)
 
static bool readXMLElementFromFile (const char *xml_file_path, const char *element_name, UT_String &element_data)
 

Detailed Description

Definition at line 41 of file UT_FileUtil.h.

Member Enumeration Documentation

Enumerator
IF_EMPTY 
ALL_CONTENTS 

Definition at line 44 of file UT_FileUtil.h.

Constructor & Destructor Documentation

UT_FileUtil::UT_FileUtil ( )
inline

Definition at line 47 of file UT_FileUtil.h.

virtual UT_FileUtil::~UT_FileUtil ( )
inlinevirtual

Definition at line 48 of file UT_FileUtil.h.

UT_FileUtil::UT_FileUtil ( const UT_FileUtil )
delete

Member Function Documentation

static int UT_FileUtil::copyDir ( const char *  srcname,
const char *  dstname 
)
static
static int UT_FileUtil::copyFile ( const char *  srcname,
const char *  dstname,
std::ostream *  error_os = nullptr 
)
static
static int UT_FileUtil::copyFileToStream ( const char *  srcname,
std::ostream &  os 
)
static
static time_t UT_FileUtil::getFileModTime ( const char *  path)
static

Returns the file modification time of the file in the given path. Returns -1 on error.

static int64 UT_FileUtil::getFileSize ( const char *  path)
static

Returns the file size of that file in the given path. Returns -1 on error.

static int UT_FileUtil::getMaxFileDescriptors ( )
static

Return the maximum number of file descriptors that are available for this process.

static time_t UT_FileUtil::getRecursiveDirMaxModTime ( const char *  path)
static

Returns the latest file modification time recusively of all files in the given path including the path itself. If the given path can be a regular file. Returns -1 if no timestamps can be retrieved.

static bool UT_FileUtil::getShortPathName ( UT_WorkBuffer result,
const char *  path 
)
static

Shorten the given path if possible. Only possibly has an effect on Windows. Returns true if successful. Upon returning false, the contents of result will be undefined.

static bool UT_FileUtil::lockFile ( int  fd)
static

Locks a file for exclusive access. Will not return until the file lock is achiveved or an error occurs. Equivalent to calling writeLockFile().

Returns
true if the file lock succeeded, and false otherwise.
Note
  • On Linux, if any file descriptor referring to this file is closed, the lock will be automatically be closed. Be very careful!
  • On Windows, this is NOT re-entrant (unlike Linux). Treat these locks as NOT re-entrant unless you want deadlocking on Windows.
static bool UT_FileUtil::makeDir ( const char *  path,
mode_t  mode = 0777,
bool  ignore_umask = false 
)
static

Make a single directory. All leading path components must exist. The function returns true if the path already exists or if the path was made.

Parameters
path
The path to create
mode
The unix file mode
ignore_umask
By default, the users umask will be used in conjunction with the mode. This parameter will force the mode to be the given value.
static bool UT_FileUtil::makeDirs ( const char *  path,
mode_t  mode = 0777,
bool  ignore_umask = false 
)
static

Make a directory and all the parent directories needed

Parameters
path
The path to create
mode
The unix file mode
ignore_umask
By default, the users umask will be used in conjunction with the mode. This parameter will force the mode to be the given value.
Examples:
FS/FS_HomeHelper.C.
static int UT_FileUtil::moveFile ( const char *  srcname,
const char *  dstname 
)
static
UT_FileUtil& UT_FileUtil::operator= ( const UT_FileUtil )
delete
static bool UT_FileUtil::readLockFile ( int  fd)
static

Locks a file for read access. Will not return until the file lock is achiveved or an error occurs.

Returns
true if the file lock succeeded, and false otherwise.
Note
  • On Linux, if any file descriptor referring to this file is closed, the lock will be automatically be closed. Be very careful!
  • On Windows, this is NOT re-entrant (unlike Linux). Treat these locks as NOT re-entrant unless you want deadlocking on Windows.
static bool UT_FileUtil::readXMLElementFromFile ( const char *  xml_file_path,
const char *  element_name,
UT_String element_data 
)
static

Parses the file in search of the given XML element and outputs its contents into the string argument. Returns true uppon success or false on failure.

static int UT_FileUtil::removeDir ( const char *  dname,
UT_RemoveDepth  depth = IF_EMPTY 
)
static
static int UT_FileUtil::removeFile ( const char *  fname)
static
static int UT_FileUtil::removeLinesFromFile ( const char *  fname,
const char *  prefix,
int  readonly = 0 
)
static
int UT_FileUtil::removeOverrideFiles ( const char *  newbasepath,
const char *  relpath,
const char *  fname,
const char *  english,
int  flags,
const char *  stripinfo = 0 
)
static int UT_FileUtil::resolveSymbolicLinks ( const char *  path,
UT_WorkBuffer contents,
bool  allow_dangling_link = false 
)
static

Follow the specified symbolic link to the contents, recursing if the contents are themselves another symbolic link. This method will fail if the specified path is not to a symbolic link, or if the link does not point to an existing file when allow_dangling_link is false.

virtual void UT_FileUtil::showError ( const char *  error,
int  severity = 2 
)
virtual
virtual int UT_FileUtil::showPrompt ( const char *  prompt)
virtual
static bool UT_FileUtil::unlockFile ( int  fd)
static

Unlocks a file that was locked for exclusive access with lockFile, above. Returns true if the unlock succeeded, and false otherwise.

static void UT_FileUtil::upDirectory ( char *  path,
int  levels 
)
static
static bool UT_FileUtil::writeLockFile ( int  fd)
static

Locks a file for write access. Will not return until the file lock is achiveved or an error occurs.

Returns
true if the file lock succeeded, and false otherwise.
Note
  • On Linux, if any file descriptor referring to this file is closed, the lock will be automatically be closed. Be very careful!
  • On Windows, this is NOT re-entrant (unlike Linux). Treat these locks as NOT re-entrant unless you want deadlocking on Windows.

The documentation for this class was generated from the following file: