JX Application Framework
|
#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"
void JAppendDirSeparator | ( | JString * | dirName | ) |
Appends the appropriate separator to the end of *dirName, if neccessary.
Returns true if it is possible to make the specified directory the working directory.
Changes the current working directory to the specified directory.
Can return JAccessDenied, JSegFault, JNameTooLong, JBadPath, JNoKernelMemory, JComponentNotDirectory, JPathContainsLoop.
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.
Concatenates path and name, inserting the appropriate separator if necessary.
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
If the directory is below the user's home directory, converts the given path to start with ~. Otherwise, returns the input string.
Converts 'path' to a path relative to 'base'. Both inputs must be absolute paths. 'path' can include a file name on the end.
Creates a symbolic link dest that points to src.
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_.
Returns true if the specified directory can be read from.
Returns true if the specified directory can be written to.
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.
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.
JString JGetCurrentDirectory | ( | ) |
Returns the full path of the current working directory.
Returns true if the specified user has a home directory.
Returns the last time that the file was modified. Can return JDirEntryDoesNotExist.
Returns the access permissions for the specified file. Can return JDirEntryDoesNotExist.
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.
Returns true if the specified user has a home directory.
Returns true if the current user has a prefs directory.
JString JGetRootDirectory | ( | ) |
Returns true if name is a valid file or a valid directory. trueName is the full, true path to name, without symbolic links.
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).
Deletes the directory and everything in it. Returns true if successful.
if !sync, *p will contain the process
Returns true if the specified name exists. (file, directory, link, etc).
Removes the specified directory. This only works if the directory is empty.
Can return JAccessDenied, JSegFault, JNameTooLong, JBadPath, JComponentNotDirectory, JDirectoryNotEmpty, JDirectoryBusy, JNoKernelMemory, JFileSystemReadOnly, JPathContainsLoop.
Renames the specified directory.
Renames the specified directory entry.
Can return JCantRenameFileToDirectory, JCantRenameAcrossFilesystems, JCantRenameToNonemptyDirectory, JFileBusy, JDirectoryCantBeOwnChild, JTooManyLinks, JComponentNotDirectory, JSegFault, JAccessDenied, JNameTooLong, JBadPath, JNoKernelMemory, JFileSystemReadOnly, JPathContainsLoop, JFileSystemFull.
Returns true if the given names point to the same inode in the file system.
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 |
||
) |
Sets the owner to the specified uid and the group to the specified gid.
Sets the access permissions for the specified file.
Can return JAccessDenied, JFileSystemReadOnly, JSegFault, JNameTooLong, JDirEntryDoesNotExist, JNoKernelMemory, JComponentNotDirectory, JPathContainsLoop.
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().
void JStripTrailingDirSeparator | ( | JString * | dirName | ) |