JX Application Framework
Loading...
Searching...
No Matches
Functions
jDirUtil.h File Reference
#include "JStdError.h"
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ace/Default_Constants.h>
#include "JString.h"
#include "jFileUtil.h"
Include dependency graph for jDirUtil.h:
This graph shows which files directly or indirectly include this file:

Functions

bool JNameUsed (const JString &name)
 
bool JSameDirEntry (const JString &name1, const JString &name2)
 
JError JRenameDirEntry (const JString &oldName, const JString &newName)
 
JError JCreateSymbolicLink (const JString &src, const JString &dest)
 
JError JGetSymbolicLinkTarget (const JString &linkFullName, JString *targetFullName)
 
JError JGetModificationTime (const JString &name, time_t *modTime)
 
JError JGetPermissions (const JString &name, mode_t *perms)
 
JError JSetPermissions (const JString &name, const mode_t perms)
 
JString JGetPermissionsString (const mode_t mode)
 
JError JGetOwnerID (const JString &name, uid_t *uid)
 
JError JGetOwnerGroup (const JString &name, gid_t *gid)
 
JError JSetOwner (const JString &name, const uid_t uid, const gid_t gid)
 
bool JDirectoryExists (const JString &dirName)
 
bool JDirectoryReadable (const JString &dirName)
 
bool JDirectoryWritable (const JString &dirName)
 
bool JCanEnterDirectory (const JString &dirName)
 
JError JCreateDirectory (const JString &dirName)
 
JError JCreateDirectory (const JString &dirName, const mode_t mode)
 
JError JRenameDirectory (const JString &oldName, const JString &newName)
 
JError JChangeDirectory (const JString &dirName)
 
JError JRemoveDirectory (const JString &dirName)
 
bool JKillDirectory (const JString &dirName, const bool sync=true, JProcess **p=nullptr)
 
JString JGetCurrentDirectory ()
 
bool JGetHomeDirectory (JString *homeDir)
 
bool JGetHomeDirectory (const JString &user, JString *homeDir)
 
bool JGetPrefsDirectory (JString *prefsDir)
 
bool JGetPrefsDirectory (const JString &user, JString *prefsDir)
 
bool JGetTempDirectory (JString *tempDir)
 
bool JGetTrueName (const JString &name, JString *trueName)
 
bool JSearchSubdirs (const JString &startPath, const JString &name, const bool isFile, const JString::Case caseSensitive, JString *path, JString *newName=nullptr, JProgressDisplay *pg=nullptr, bool *userCancelled=nullptr)
 
JString JGetUniqueDirEntryName (const JString &path, const JString &namePrefix, const JUtf8Byte *nameSuffix=nullptr, const JIndex startIndex=1)
 
JError JCreateTempDirectory (const JString *path, const JString *prefix, JString *fullName)
 
JString JCombinePathAndName (const JString &path, const JString &name)
 
bool JSplitPathAndName (const JString &fullName, JString *path, JString *name)
 
void JAppendDirSeparator (JString *dirName)
 
void JStripTrailingDirSeparator (JString *dirName)
 
void JCleanPath (JString *path)
 
JString JGetRootDirectory ()
 
bool JIsRootDirectory (const JString &dirName)
 
bool JIsAbsolutePath (const JString &path)
 
bool JIsRelativePath (const JString &path)
 
bool JConvertToAbsolutePath (const JString &path, const JString &base, JString *result)
 
JString JConvertToRelativePath (const JString &path, const JString &base)
 
bool JExpandHomeDirShortcut (const JString &path, JString *result, JString *homeDir=nullptr, JSize *homeLength=nullptr)
 
JString JConvertToHomeDirShortcut (const JString &path)
 
JString JGetClosestDirectory (const JString &origDirName, const bool requireWrite=false, const JString *basePath=nullptr)
 
JError JCreateTempDirectory (JString *fullName)
 

Function Documentation

◆ JAppendDirSeparator()

void JAppendDirSeparator ( JString dirName)

Appends the appropriate separator to the end of *dirName, if neccessary.

◆ JCanEnterDirectory()

bool JCanEnterDirectory ( const JString dirName)

Returns true if it is possible to make the specified directory the working directory.

◆ JChangeDirectory()

JError JChangeDirectory ( const JString dirName)

Changes the current working directory to the specified directory.

Can return JAccessDenied, JSegFault, JNameTooLong, JBadPath, JNoKernelMemory, JComponentNotDirectory, JPathContainsLoop.

◆ JCleanPath()

void JCleanPath ( JString path)

Removes fluff from the given path:

/./
trailing /.

We can't remove /x/../ because if x is a symlink, the result would not be the same directory.

This is required to work for files and directories.

◆ JCombinePathAndName()

JString JCombinePathAndName ( const JString path,
const JString name 
)

Concatenates path and name, inserting the appropriate separator if necessary.

◆ JConvertToAbsolutePath()

bool JConvertToAbsolutePath ( const JString path,
const JString base,
JString result 
)

Attempts to convert 'path' to a full path. Returns true if successful.

If path begins with '/', there is nothing to do. If path begins with '~', the user's home directory is inserted. Otherwise, if base is not empty, it is prepended. Otherwise, the result of JGetCurrentDirectory() is prepended.

As a final check, it calls JNameUsed() to check that the result exists. (This allows one to pass in a path+name as well as only a path.)

If it is possible to expand the path, *result will contain the expanded path, even if JNameUsed() fails

◆ JConvertToHomeDirShortcut()

JString JConvertToHomeDirShortcut ( const JString path)

If the directory is below the user's home directory, converts the given path to start with ~. Otherwise, returns the input string.

◆ JConvertToRelativePath()

JString JConvertToRelativePath ( const JString origPath,
const JString origBase 
)

Converts 'path' to a path relative to 'base'. Both inputs must be absolute paths. 'path' can include a file name on the end.

◆ JCreateDirectory() [1/2]

JError JCreateDirectory ( const JString dirName)

◆ JCreateDirectory() [2/2]

JError JCreateDirectory ( const JString dirName,
const mode_t  mode 
)

◆ JCreateSymbolicLink()

JError JCreateSymbolicLink ( const JString src,
const JString dest 
)

Creates a symbolic link dest that points to src.

◆ JCreateTempDirectory() [1/2]

JError JCreateTempDirectory ( const JString path,
const JString prefix,
JString fullName 
)

Creates a unique directory in the specified directory. If path is empty, it uses the system's scratch directory. If prefix is empty, uses temp_dir_.

◆ JCreateTempDirectory() [2/2]

JError JCreateTempDirectory ( JString fullName)
inline

◆ JDirectoryExists()

bool JDirectoryExists ( const JString dirName)

Returns true if the specified directory exists.

◆ JDirectoryReadable()

bool JDirectoryReadable ( const JString dirName)

Returns true if the specified directory can be read from.

◆ JDirectoryWritable()

bool JDirectoryWritable ( const JString dirName)

Returns true if the specified directory can be written to.

◆ JExpandHomeDirShortcut()

bool JExpandHomeDirShortcut ( const JString path,
JString result,
JString homeDir,
JSize homeLength 
)

If the given path begins with ~ or ~x, this is replaced by the appropriate home directory, if it exists. Otherwise, false is returned and *result is empty.

If homeDir != nullptr, it is set to the home directory that was specified by the ~. If homeLength != nullptr it is set to the number of characters at the start of path that specified the home directory.

This function does not check that the resulting expanded path is valid.

If path doesn't begin with ~, returns true, *result = path, *homeDir is empty, and *homeLength = 0.

◆ JGetClosestDirectory()

JString JGetClosestDirectory ( const JString origDirName,
const bool  requireWrite,
const JString basePath 
)

If the directory does not exist, go as far down the directory tree as possible towards the specified directory.

As an example, /usr/include/junk doesn't normally exist, so it will return /usr/include.

If a partial path is passed in, it is assumed to be relative to the given basePath. If this is empty, the current working directory is used instead. If the base path is valid, a partial path will be returned.

If the path begins with ~ and the home directory exists, a ~ path will be returned.

◆ JGetCurrentDirectory()

JString JGetCurrentDirectory ( )

Returns the full path of the current working directory.

◆ JGetHomeDirectory() [1/2]

bool JGetHomeDirectory ( const JString user,
JString homeDir 
)

Returns true if the specified user has a home directory.

◆ JGetHomeDirectory() [2/2]

bool JGetHomeDirectory ( JString homeDir)

Returns true if the current user has a home directory.

◆ JGetModificationTime()

JError JGetModificationTime ( const JString name,
time_t *  modTime 
)

Returns the last time that the file was modified. Can return JDirEntryDoesNotExist.

◆ JGetOwnerGroup()

JError JGetOwnerGroup ( const JString name,
gid_t *  gid 
)

Returns the gid of the owner.

◆ JGetOwnerID()

JError JGetOwnerID ( const JString name,
uid_t *  uid 
)

Returns the uid of the owner.

◆ JGetPermissions()

JError JGetPermissions ( const JString name,
mode_t *  perms 
)

Returns the access permissions for the specified file. Can return JDirEntryDoesNotExist.

◆ JGetPermissionsString()

JString JGetPermissionsString ( const mode_t  mode)

Converts the low 9 bits of the st_mode field from stat() to a string using the same format as ls.

◆ JGetPrefsDirectory() [1/2]

bool JGetPrefsDirectory ( const JString user,
JString prefsDir 
)

Returns true if the specified user has a home directory.

◆ JGetPrefsDirectory() [2/2]

bool JGetPrefsDirectory ( JString prefsDir)

Returns true if the current user has a prefs directory.

◆ JGetRootDirectory()

JString JGetRootDirectory ( )

◆ JGetSymbolicLinkTarget()

JError JGetSymbolicLinkTarget ( const JString linkFullName,
JString targetFullName 
)

◆ JGetTempDirectory()

bool JGetTempDirectory ( JString tempDir)

Returns the system's scratch directory.

◆ JGetTrueName()

bool JGetTrueName ( const JString name,
JString trueName 
)

Returns true if name is a valid file or a valid directory. trueName is the full, true path to name, without symbolic links.

◆ JGetUniqueDirEntryName()

JString JGetUniqueDirEntryName ( const JString path,
const JString namePrefix,
const JUtf8Byte nameSuffix,
const JIndex  startIndex 
)
Just like tmpnam, this function is not safe, because it does not
perform atomic check-create.  The safe functions are
JCreateTempDirectory() and JCreateTempFile().

Returns a unique name, starting with namePrefix, for use in the specified directory. If path is empty, it tries to use /tmp. If this fails, it uses the current working directory.

nameSuffix can be nullptr.

We ignore the possibility of not finding a valid name because the file system will fill up long before we run out of possibilities.

startIndex lets you optimize when creating a large number of temporary files. By setting startIndex to the number of files that you have already created, you make the process of generating the file names O(N) instead of O(N^2).

◆ JIsAbsolutePath()

bool JIsAbsolutePath ( const JString path)

◆ JIsRelativePath()

bool JIsRelativePath ( const JString path)

◆ JIsRootDirectory()

bool JIsRootDirectory ( const JString dirName)

◆ JKillDirectory()

bool JKillDirectory ( const JString dirName,
const bool  sync,
JProcess **  p 
)

Deletes the directory and everything in it. Returns true if successful.

if !sync, *p will contain the process

◆ JNameUsed()

bool JNameUsed ( const JString name)

Returns true if the specified name exists. (file, directory, link, etc).

◆ JRemoveDirectory()

JError JRemoveDirectory ( const JString dirName)

Removes the specified directory. This only works if the directory is empty.

Can return JAccessDenied, JSegFault, JNameTooLong, JBadPath, JComponentNotDirectory, JDirectoryNotEmpty, JDirectoryBusy, JNoKernelMemory, JFileSystemReadOnly, JPathContainsLoop.

◆ JRenameDirectory()

JError JRenameDirectory ( const JString oldName,
const JString newName 
)

Renames the specified directory.

◆ JRenameDirEntry()

JError JRenameDirEntry ( const JString oldName,
const JString newName 
)

◆ JSameDirEntry()

bool JSameDirEntry ( const JString name1,
const JString name2 
)

Returns true if the given names point to the same inode in the file system.

◆ JSearchSubdirs()

bool JSearchSubdirs ( const JString startPath,
const JString name,
const bool  isFile,
const JString::Case  caseSensitive,
JString path,
JString newName = nullptr,
JProgressDisplay pg = nullptr,
bool userCancelled = nullptr 
)

◆ JSetOwner()

JError JSetOwner ( const JString name,
const uid_t  uid,
const gid_t  gid 
)

Sets the owner to the specified uid and the group to the specified gid.

◆ JSetPermissions()

JError JSetPermissions ( const JString name,
const mode_t  perms 
)

◆ JSplitPathAndName()

bool JSplitPathAndName ( const JString fullName,
JString path,
JString name 
)

Splits fullName into a path and name.

If fullName doesn't contain a directory separator, it returns false and *path is the result of JGetCurrentDirectory().

◆ JStripTrailingDirSeparator()

void JStripTrailingDirSeparator ( JString dirName)