JX Application Framework
Loading...
Searching...
No Matches
Functions
jDirUtil_UNIX.cpp File Reference
#include "jDirUtil.h"
#include "JThisProcess.h"
#include "JDirInfo.h"
#include "JProgressDisplay.h"
#include "JLatentPG.h"
#include "JSimpleProcess.h"
#include "JStringIterator.h"
#include "jGlobals.h"
#include "JStdError.h"
#include <pwd.h>
#include "jErrno.h"
#include "jMissingProto.h"
#include "jAssert.h"
Include dependency graph for jDirUtil_UNIX.cpp:

Functions

bool JNameUsed (const JString &name)
 
bool JSameDirEntry (const JString &name1, const JString &name2)
 
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)
 
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)
 
JError JCreateSymbolicLink (const JString &src, const JString &dest)
 
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 JRenameDirEntry (const JString &oldName, const JString &newName)
 
JError JChangeDirectory (const JString &dirName)
 
JError JRemoveDirectory (const JString &dirName)
 
bool JKillDirectory (const JString &dirName, const bool sync, JProcess **p)
 
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)
 
JError JCreateTempDirectory (const JString *path, const JString *prefix, JString *fullName)
 
bool JGetTrueName (const JString &name, JString *trueName)
 
void JCleanPath (JString *path)
 
bool JIsAbsolutePath (const JString &path)
 
JString JGetRootDirectory ()
 
bool JIsRootDirectory (const JString &dirName)
 
bool JConvertToAbsolutePath (const JString &path, const JString &base, JString *result)
 
JString JConvertToRelativePath (const JString &origPath, const JString &origBase)
 
bool JExpandHomeDirShortcut (const JString &path, JString *result, JString *homeDir, JSize *homeLength)
 
JError JGetSymbolicLinkTarget (const JString &linkFullName, JString *targetFullName)
 

Function Documentation

◆ 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.

◆ 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

◆ 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()

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_.

◆ 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.

◆ 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.

◆ 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.

◆ JIsAbsolutePath()

bool JIsAbsolutePath ( 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.

◆ 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.

◆ 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 
)