Functions for dealing with files.
Definition at line 26 of file VuoFileUtilities.hh.
Classes | |
class | Archive |
An archive of files. More... | |
class | File |
A file in either a directory or an archive. More... | |
Static Public Member Functions | |
static void | splitPath (string path, string &dir, string &file, string &extension) |
Splits path into its directory, file name, and file extension. | |
static void | canonicalizePath (string &path) |
Transforms path to a standard format. | |
static bool | arePathsEqual (string path1, string path2) |
Returns true if the paths refer to the same location. | |
static string | getAbsolutePath (const string &path) |
Returns path itself if it's already an absolute path, or else an absolute path consisting of path relative to the current working directory. | |
static bool | isAbsolutePath (const string &path) |
Returns true if path is an absolute path (regardless of whether the file exists), false if path is a relative path. | |
static string | makeTmpFile (string file, string extension, string directory="") |
Creates a new temporary file with mode 0600, avoiding any name conflicts with existing files. | |
static string | makeTmpDir (string prefix) |
Creates a new temporary directory with mode 0700, whose final path element begins with prefix and has a unique extension (avoiding name conflicts with existing files). | |
static string | makeTmpDirOnSameVolumeAsPath (string path) |
Creates a new temporary directory, avoiding any name conflicts with existing files. | |
static string | getTmpDir (void) |
For non-sandboxed processes, returns the user's private temporary directory if avaialble (e.g., /var/folders/f3/v1j4zqhs5jz5757t0rmh7jj80000gn/T ), otherwise returns the system temporary directory (/tmp ). | |
static void | makeDir (string path) |
Creates a new directory (and parent directories if needed), if it doesn't already exist. | |
static string | getVuoFrameworkPath (void) |
Returns the absolute path of Vuo.framework (including the Vuo.framework directory name without a trailing slash), or an empty string if Vuo.framework cannot be located. | |
static string | getVuoRunnerFrameworkPath (void) |
Returns the absolute path of VuoRunner.framework (including the VuoRunner.framework directory name without a trailing slash), or an empty string if VuoRunner.framework cannot be located. | |
static string | getCompositionLocalModulesPath (const string &compositionPath) |
Returns the path of the composition-local Modules folder for a composition located at compositionPath. | |
static string | getUserModulesPath (void) |
Returns the filesystem path to the user-specific Vuo Modules folder (without a trailing slash). | |
static string | getSystemModulesPath (void) |
Returns the filesystem path to the system-wide Vuo Modules folder (without a trailing slash). | |
static string | getCachePath (void) |
Returns the filesystem path to the folder that Vuo uses to cache data (without a trailing slash). | |
static bool | isInstalledAsModule (const string &path) |
Returns true if path (a source file or compiled module) is located in a Modules folder. | |
static void | preserveOriginalFileName (string &fileContents, string originalFileName) |
Saves originalFileName into fileContents so that, when fileContents is written to some other file path, originalFileName will still be the name that shows up in compile errors/warnings and in the __FILE__ macro. | |
static size_t | getFirstInsertionIndex (string s) |
Returns the first index at which content can be inserted into a string that was read from a file. | |
static string | readStdinToString (void) |
Reads from standard input into a string until the end-of-file is reached. | |
static string | readFileToString (string path) |
Reads the whole contents of the file into a string. | |
static void | writeRawDataToFile (const char *data, size_t numBytes, string file) |
Writes the array of bytes to the file. | |
static void | writeStringToFile (string s, string file) |
Writes the string to the file. | |
static void | writeStringToFileSafely (string s, string path) |
Saves to file using the standard Unix procedure (write to temporary file, then rename). | |
static bool | fileExists (string path) |
Returns true if the file exists. | |
static bool | dirExists (string path) |
Returns true if path exists and is a directory. | |
static bool | isSymlink (string path) |
Returns true if path exists and is a symlink. | |
static bool | fileIsReadable (string path) |
Returns true if the file or directory is readable. | |
static bool | fileContainsReadableData (string path) |
Returns true if the file exists, can be opened, and has a size of more than 0 bytes. | |
static void | createFile (string path) |
Creates the file if it does not exist already; otherwise, has no effect on the file. | |
static void | deleteFile (string path) |
Deletes the file or directory if it exists and, if a directory, is empty; otherwise, has no effect. | |
static void | deleteDir (string path) |
Deletes the directory and its contents if the directory exists; otherwise, has no effect. | |
static void | moveFile (string fromPath, string toPath) |
Moves the file from fromPath to toPath. | |
static void | moveFileToTrash (string filePath) |
Moves the specified file to the user's trash folder. | |
static void | copyFile (string fromPath, string toPath, bool preserveMetadata=false) |
Copies the file from fromPath to toPath, preserving the file's mode. | |
static void | copyDirectory (string fromPath, string toPath) |
Recursively copies the provided file or directory from fromPath to toPath . | |
static string | calculateFileSHA256 (const string &path) |
Returns the SHA-256 hash of the file at path as a string of hex digits. | |
static double | getFileLastModifiedInSeconds (string path) |
Returns the time that the file was last modified, in seconds from a reference date, with fractional seconds up to microsecond resolution if the filesystem supports it. | |
static double | getSecondsSinceFileLastAccessed (string path) |
Returns the time since the file was last accessed or modified (whichever is more recent), in seconds, with fractional seconds up to microsecond resolution if the filesystem supports it. | |
static set< File * > | findAllFilesInDirectory (string dirPath, set< string > archiveExtensions=set< string >(), bool shouldSearchRecursively=false) |
Searches a directory for files. | |
static set< File * > | findFilesInDirectory (string dirPath, set< string > extensions, set< string > archiveExtensions=set< string >()) |
Searches a directory for files with a given extension. | |
static set< File * > | findAllFilesInArchive (string archivePath) |
Recursively searches an archive for files. | |
static set< File * > | findFilesInArchive (string archivePath, string dirPath, set< string > extensions) |
Recursively searches an archive for files within a given directory and with a given extension. | |
static string | getArchiveFileContentsAsString (string archivePath, string filePath) |
Returns the contents of a file within an archive. | |
static size_t | getAvailableSpaceOnVolumeContainingPath (string path) |
Returns the available space, in bytes, on the volume containing the specified path. | |
static void | adHocCodeSign (string path, vector< string > environment, string entitlementsPath="") |
Ad-hoc code-signs the specified binary. | |
static void | focusProcess (pid_t pid, bool force=false) |
Attempts to focus the specified pid (i.e., bring all its windows to the front and make one of them key). | |
static void | executeProcess (vector< string > processAndArgs, vector< string > environment={}) |
Launches another process and waits for it to finish. | |
static bool | isCompositionExtension (string extension) |
Returns true if the given extension (without leading dot) is a Vuo composition file. | |
static set< string > | getCFamilySourceExtensions (void) |
Returns C/C++/Objective-C/Objective-C++ source file extensions (without a leading dot). | |
static bool | isCFamilySourceExtension (string extension) |
Returns true if the given extension (without leading dot) is a C/C++/Objective-C/Objective-C++ source file. | |
static bool | isCPlusPlusSourceExtension (string extension) |
Returns true if the given extension (without leading dot) is for a C++ source file. | |
static bool | isObjectiveCSourceExtension (string extension) |
Returns true if the given extension (without leading dot) is for an Objective-C source file. | |
static bool | isObjectiveCPlusPlusSourceExtension (string extension) |
Returns true if the given extension (without leading dot) is for an Objective-C++ source file. | |
static set< string > | getIsfSourceExtensions (void) |
Returns ISF source file extensions (without a leading dot). | |
static bool | isIsfSourceExtension (string extension) |
Returns true if the given extension (without leading dot) is an ISF source file. | |
|
static |
Ad-hoc code-signs the specified binary.
Definition at line 1100 of file VuoFileUtilities.cc.
|
static |
Returns true if the paths refer to the same location.
This handles different formats for the same path (by comparing the canonicalized paths). It does not follow symlinks.
Definition at line 96 of file VuoFileUtilities.cc.
|
static |
Returns the SHA-256 hash of the file at path
as a string of hex digits.
VuoException |
Definition at line 811 of file VuoFileUtilities.cc.
|
static |
Transforms path to a standard format.
The returned path is absolute if path is absolute, relative if path is relative.
Definition at line 77 of file VuoFileUtilities.cc.
|
static |
Recursively copies the provided file or directory from fromPath
to toPath
.
Preserves symlinks (rather than copying their target files).
VuoException | The file couldn't be copied. |
Definition at line 775 of file VuoFileUtilities.cc.
|
static |
Copies the file from fromPath to toPath, preserving the file's mode.
If preserveMetadata is true and toPath already exists, the file's inode and stat info is preserved, thus so are any locks on the file.
VuoException | The file couldn't be copied. |
Definition at line 740 of file VuoFileUtilities.cc.
|
static |
Creates the file if it does not exist already; otherwise, has no effect on the file.
VuoException | The user doesn't have permission to create the file. |
Definition at line 653 of file VuoFileUtilities.cc.
|
static |
Deletes the directory and its contents if the directory exists; otherwise, has no effect.
Definition at line 675 of file VuoFileUtilities.cc.
|
static |
Deletes the file or directory if it exists and, if a directory, is empty; otherwise, has no effect.
Definition at line 665 of file VuoFileUtilities.cc.
|
static |
Returns true if path
exists and is a directory.
If path
is a symlink or macOS Alias, it is dereferenced.
Definition at line 582 of file VuoFileUtilities.cc.
|
static |
Launches another process and waits for it to finish.
If the exit status is nonzero, throws an exception containing stdout and stderr.
The optional environment
argument should consist of strings of the form key=value
.
VuoException |
Definition at line 1415 of file VuoFileUtilities.cc.
|
static |
Returns true if the file exists, can be opened, and has a size of more than 0 bytes.
If path
is a symlink or macOS Alias, it is dereferenced.
Definition at line 622 of file VuoFileUtilities.cc.
|
static |
Returns true if the file exists.
If path
is a symlink or macOS Alias, it is dereferenced.
Definition at line 568 of file VuoFileUtilities.cc.
|
static |
Returns true if the file or directory is readable.
If path
is a symlink or macOS Alias, it is dereferenced.
Definition at line 608 of file VuoFileUtilities.cc.
|
static |
Recursively searches an archive for files.
archivePath | The archive to search in. |
Definition at line 993 of file VuoFileUtilities.cc.
|
static |
Searches a directory for files.
If dirPath
is a symlink or macOS Alias, it is dereferenced.
dirPath | The directory to search in. |
archiveExtensions | The file extensions for archives to search in. Any archive with one of these extensions found in the top level of the directory will be searched recursively. |
shouldSearchRecursively | If true, the directory will be searched searched recursively. If false, only the top level is searched. |
VuoException | The directory couldn't be read. |
Definition at line 888 of file VuoFileUtilities.cc.
|
static |
Recursively searches an archive for files within a given directory and with a given extension.
archivePath | The archive to search in. |
dirPath | The directory to search in within the archive. The path should be relative to the archive's root. The path should omit the trailing file separator (e.g. "examples" not "examples/"). |
extensions | The file extensions to search for, without the '.' character (e.g. "bc" not ".bc"). |
Definition at line 1034 of file VuoFileUtilities.cc.
|
static |
Searches a directory for files with a given extension.
dirPath | The directory to search in. Only the top level is searched. |
archiveExtensions | The file extensions for archives to search in. Any archive with one of these extensions found in the top level of the directory will be searched recursively. |
extensions | The file extensions to search for, without the '.' character (e.g. "bc" not ".bc"). |
Definition at line 966 of file VuoFileUtilities.cc.
|
static |
Attempts to focus the specified pid
(i.e., bring all its windows to the front and make one of them key).
This function may only be called on the main thread.
Definition at line 1402 of file VuoFileUtilities.cc.
|
static |
Returns path itself if it's already an absolute path, or else an absolute path consisting of path relative to the current working directory.
Definition at line 107 of file VuoFileUtilities.cc.
|
static |
Returns the contents of a file within an archive.
If the file doesn't exist, returns an empty string.
archivePath | The archive containing the file. |
filePath | The file. The path should be relative to the archive's root. |
Definition at line 1070 of file VuoFileUtilities.cc.
|
static |
Returns the available space, in bytes, on the volume containing the specified path.
path
should be an absolute POSIX path. Its last few path components needn't exist.
VuoException |
Definition at line 1092 of file VuoFileUtilities.cc.
|
static |
Returns the filesystem path to the folder that Vuo uses to cache data (without a trailing slash).
The folder does not necessarily exist yet.
If the process is running in a sandbox, the user's home folder may not be available, in which case this method returns an empty string.
Definition at line 411 of file VuoFileUtilities.cc.
|
static |
Returns C/C++/Objective-C/Objective-C++ source file extensions (without a leading dot).
Definition at line 1518 of file VuoFileUtilities.cc.
|
static |
Returns the path of the composition-local Modules folder for a composition located at compositionPath.
(The composition file need not actually exist.)
If the composition is installed as a subcomposition (it's located in a folder called Modules), returns that folder. Otherwise, returns a Modules folder located in the same folder as the composition.
Definition at line 360 of file VuoFileUtilities.cc.
|
static |
Returns the time that the file was last modified, in seconds from a reference date, with fractional seconds up to microsecond resolution if the filesystem supports it.
This is useful for checking which of two files was modified more recently.
Definition at line 845 of file VuoFileUtilities.cc.
|
static |
Returns the first index at which content can be inserted into a string that was read from a file.
This comes after the Unicode BOM, if present.
Definition at line 453 of file VuoFileUtilities.cc.
|
static |
Returns ISF source file extensions (without a leading dot).
Definition at line 1569 of file VuoFileUtilities.cc.
|
static |
Returns the time since the file was last accessed or modified (whichever is more recent), in seconds, with fractional seconds up to microsecond resolution if the filesystem supports it.
Definition at line 856 of file VuoFileUtilities.cc.
|
static |
Returns the filesystem path to the system-wide Vuo Modules folder (without a trailing slash).
Definition at line 398 of file VuoFileUtilities.cc.
|
static |
For non-sandboxed processes, returns the user's private temporary directory if avaialble (e.g., /var/folders/f3/v1j4zqhs5jz5757t0rmh7jj80000gn/T
), otherwise returns the system temporary directory (/tmp
).
For sandboxed processes, returns the sandbox container directory (e.g., /Users/me/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data
).
The returned path does not include a trailing slash.
Definition at line 201 of file VuoFileUtilities.cc.
|
static |
Returns the filesystem path to the user-specific Vuo Modules folder (without a trailing slash).
The folder does not necessarily exist yet.
If the process is running in a sandbox, the user's home folder may not be available, in which case this method returns an empty string.
Definition at line 386 of file VuoFileUtilities.cc.
|
static |
Returns the absolute path of Vuo.framework (including the Vuo.framework
directory name without a trailing slash), or an empty string if Vuo.framework cannot be located.
For a C version accessible from nodes and libraries, see VuoGetFrameworkPath.
Definition at line 335 of file VuoFileUtilities.cc.
|
static |
Returns the absolute path of VuoRunner.framework (including the VuoRunner.framework
directory name without a trailing slash), or an empty string if VuoRunner.framework cannot be located.
Definition at line 346 of file VuoFileUtilities.cc.
|
static |
Returns true if path is an absolute path (regardless of whether the file exists), false if path is a relative path.
Definition at line 128 of file VuoFileUtilities.cc.
|
static |
Returns true if the given extension (without leading dot) is a C/C++/Objective-C/Objective-C++ source file.
Definition at line 1535 of file VuoFileUtilities.cc.
|
static |
Returns true if the given extension (without leading dot) is a Vuo composition file.
Definition at line 1510 of file VuoFileUtilities.cc.
|
static |
Returns true if the given extension (without leading dot) is for a C++ source file.
Definition at line 1544 of file VuoFileUtilities.cc.
|
static |
Returns true if path (a source file or compiled module) is located in a Modules folder.
Definition at line 423 of file VuoFileUtilities.cc.
|
static |
Returns true if the given extension (without leading dot) is an ISF source file.
Definition at line 1582 of file VuoFileUtilities.cc.
|
static |
Returns true if the given extension (without leading dot) is for an Objective-C++ source file.
Definition at line 1561 of file VuoFileUtilities.cc.
|
static |
Returns true if the given extension (without leading dot) is for an Objective-C source file.
Definition at line 1553 of file VuoFileUtilities.cc.
|
static |
Returns true if path
exists and is a symlink.
Definition at line 596 of file VuoFileUtilities.cc.
|
static |
Creates a new directory (and parent directories if needed), if it doesn't already exist.
VuoException | The directory couldn't be created. |
Definition at line 236 of file VuoFileUtilities.cc.
|
static |
Creates a new temporary directory with mode 0700, whose final path element begins with prefix
and has a unique extension (avoiding name conflicts with existing files).
prefix
shouldn't contain any slashes.
Returns the path of the directory (without a trailing slash).
Definition at line 166 of file VuoFileUtilities.cc.
|
static |
Creates a new temporary directory, avoiding any name conflicts with existing files.
The temporary directory will be on the same filesystem as the specified path, to facilitate using rename()
(for example). onSameVolumeAsPath
needn't already exist.
Returns the path of the directory (without a trailing slash).
Definition at line 185 of file VuoFileUtilities.cc.
|
static |
Creates a new temporary file with mode 0600, avoiding any name conflicts with existing files.
Creates the file in the specified directory
if one is provided, or in the user's temporary directory otherwise.
Returns the path of the file.
Definition at line 140 of file VuoFileUtilities.cc.
|
static |
Moves the file from fromPath to toPath.
VuoException | The file couldn't be moved. |
Definition at line 712 of file VuoFileUtilities.cc.
|
static |
Moves the specified file to the user's trash folder.
VuoException | The file couldn't be moved. |
Definition at line 724 of file VuoFileUtilities.cc.
|
static |
Saves originalFileName into fileContents so that, when fileContents is written to some other file path, originalFileName will still be the name that shows up in compile errors/warnings and in the __FILE__
macro.
This function inserts a preprocessor directive at the beginning of fileContents. Any modifications to fileContents after this function is called should keep the preprocessor directive on the first line.
Definition at line 444 of file VuoFileUtilities.cc.
|
static |
Reads the whole contents of the file into a string.
VuoException | The file couldn't be read. |
Definition at line 492 of file VuoFileUtilities.cc.
|
static |
Reads from standard input into a string until the end-of-file is reached.
Definition at line 475 of file VuoFileUtilities.cc.
|
static |
Splits path
into its directory, file name, and file extension.
[in] | path | The path to split. |
[out] | dir | The directory in path , if any. Ends with a file separator (e.g. '/') if there was one in path . |
[out] | file | The file name in path , if any. |
[out] | extension | The file extension in path , if any. Does not include the '.' character. |
Definition at line 41 of file VuoFileUtilities.cc.
|
static |
Writes the array of bytes to the file.
If the file already exists, it gets overwritten.
VuoException | The file couldn't be written. |
Definition at line 516 of file VuoFileUtilities.cc.
|
static |
Writes the string to the file.
If the file already exists, it gets overwritten.
VuoException | The file couldn't be written. |
Definition at line 539 of file VuoFileUtilities.cc.
|
static |
Saves to file using the standard Unix procedure (write to temporary file, then rename).
This prevents the destination file from becoming corrupted if the write fails.
If the file already exists, it gets overwritten.
VuoException | The file couldn't be written. |
Definition at line 552 of file VuoFileUtilities.cc.