l0.DependencyControl.file-ops¶
Functions¶
createTempDir ¶
Creates a unique temporary directory and returns its path.
Returns:
tempDirPathstring? — Absolute path to the created temporary directory, or nil if it couldn't be created.errstring? — Error message if the directory couldn't be created.
getTempDir ¶
Generates a unique temporary directory path that does not exist yet.
Returns:
tempDirPathstring— Absolute path to a unique, not-yet-existing temporary directory.
remove ¶
Removes one or more files/directories and optionally reschedules failed removals.
| param | type | description |
|---|---|---|
| paths | string|(string|string[])[] |
Path, or list of paths (each a string or an array of path segments). |
| recurse? | boolean |
Recurse into directories (default false, so a non-empty directory is not removed). |
| reSchedule? | boolean |
Reschedule failed removals for the next restart. |
Returns:
overallSuccessboolean? — True if all succeeded, false if any were rescheduled, nil on hard failure.detailstable— Per-path result tables keyed by path.firstErrstring? — The first error encountered.
runScheduledRemoval ¶
Replays removals previously scheduled by remove().
| param | type | description |
|---|---|---|
| configDir? | string |
Directory holding the FileOps config (defaults to the configured dir). |
Returns:
successboolean?errstring?
copy ¶
Copies a file to a target path.
| param | type | description |
|---|---|---|
| source | string |
|
| target | string |
|
| clobber? | boolean |
Overwrite an existing target file. |
Returns:
successbooleanerrstring?
listDir ¶
Lists the names of a directory's entries, excluding . and ...
| param | type | description |
|---|---|---|
| dirPath | string|string[] |
Path or path segments of the directory. |
Returns:
entriesstring[]? — The entry names, or nil when the path isn't a directory.errstring?
listFilesRecursive ¶
Recursively collects all files below a directory.
| param | type | description |
|---|---|---|
| dirPath | string|string[] |
Path or path segments of the directory to walk. |
Returns:
filesstring[]? — Full paths of every file below the directory (joined onto the given path), or nil when it can't be listed.errstring?
joinPath ¶
Joins and resolves multiple path segments into a single path string.
| param | type | description |
|---|---|---|
| ... | string|string[] |
One or more path segments, or arrays of path segments. |
Returns:
joinedPathstring? — The path segments joined by OS-specific separators, or nil on error.errstring?
pathSegments ¶
Returns an iterator over the non-empty components of a path, split on any separator.
| param | type | description |
|---|---|---|
| path | string |
Returns:
iteratorfun(): string?
move ¶
Moves a file to a target path, optionally replacing existing targets.
| param | type | description |
|---|---|---|
| source | string |
|
| target | string |
|
| overwrite? | boolean |
Replace an existing target file. |
Returns:
successbooleanerrstring?
readFile ¶
Reads and returns the full contents of a file.
| param | type | description |
|---|---|---|
| path | string|string[] |
Path or path segments to the file to read. |
Returns:
datastring? — The contents of the file, or nil if an error occurred.errstring? — An error message if an error occurred.
writeFile ¶
Writes data to a file, creating the file if it doesn't exist and optionally overwriting existing files.
| param | type | description |
|---|---|---|
| path | string|string[] |
Path or path segments to the file to write. |
| data | string |
The data to write to the file. |
| clobber? | boolean |
Overwrite the file if it already exists (default false). |
Returns:
successboolean— True if the file was written successfully.errstring?
getHash ¶
Reads a file and computes the hash of its contents.
| param | type | description |
|---|---|---|
| fileName | string|string[] |
Path or path segments to the file to hash. |
| hashType? | HashType | The hash algorithm to use (default Sha1). |
Returns:
hexDigeststring? — The lowercase hex digest, or nil if an error occurred.errstring? — An error message if an error occurred.
verifyHash ¶
Reads a file and verifies its contents match an expected hash.
| param | type | description |
|---|---|---|
| fileName | string|string[] |
Path or path segments to the file to verify. |
| hash | string |
The expected hex digest (compared case-insensitively). |
| hashType? | HashType | The hash algorithm to use (default Sha1). |
Returns:
matchboolean? — True on match, false on mismatch, or nil on error.errstring? — The mismatch detail or error message.
rmdir ¶
Removes a directory, by default together with everything it contains.
| param | type | description |
|---|---|---|
| path | string|string[] |
Path or path segments to the directory to remove. |
| recurse? | boolean |
Remove the directory's contents first (default true); when false, only an already-empty directory is removed. |
Returns:
successboolean? — True on success, or nil on error.errstring? — An error message when the path is empty, doesn't exist, isn't a directory, or something couldn't be removed.
mkdir ¶
Creates a directory.
| param | type | description |
|---|---|---|
| path | string|string[] |
Path or path segments to the directory to create. |
| isFile | boolean |
Whether the path is a file path (discards the last segment when checking/creating the directory). |
| recurse? | boolean |
Also create any missing parent directories (default false). |
Returns:
createdboolean? — True if created, false if it already existed, nil if an error occurred.dirPathOrErrorstring— The existing/created directory path, or an error message.
getAttributes ¶
Retrieves file or directory attributes along with the parsed components of its path.
| param | type | description |
|---|---|---|
| path | string|string[] |
Either a path or an array of path segments. |
| key? | string |
Attribute name to retrieve (e.g. "mode", "size", "modification"), or nil for the full attribute table. |
Returns:
infoFileOpsAttributesInfo? — The attributes and path components, or nil on a hard error (an invalid path or an lfs failure). A path that simply doesn't exist is not an error:info.attris then false.errstring? — An error message, present only when info is nil.
attributes ¶
Deprecated — Use
getAttributes, which returns a single info table plus an error message.
Retrieves file or directory attributes.
| param | type | description |
|---|---|---|
| path | string|string[] |
Either a path or an array of path segments. |
| key? | string |
Attribute name to retrieve (e.g. "mode", "size", "modification"), or nil for the full attribute table. |
Returns:
attrtable|string|number|boolean|nil— The requested attribute(s), false if absent, or nil on error.fullPathstring— The validated full path, or an error message if the path was invalid.devicestring? — The device component of the path.dirstring? — The directory component of the path.filestring? — The file name component of the path.
exists ¶
Checks whether a file or directory exists and optionally verifies its type.
| param | type | description |
|---|---|---|
| path | string|string[] |
Either a path or an array of path segments. |
| expectedMode? | string |
If specified, the required type of the filesystem entry. |
Returns:
existsboolean? — True if it exists and matches the expected type, false if not, nil on error.errstring? — An error message if the file doesn't exist or is of the wrong type.
validateFullPath ¶
Validates and normalizes an absolute filesystem path.
| param | type | description |
|---|---|---|
| path | string|string[] |
Either a path or an array of path segments. |
| checkFileExt? | boolean |
Require the path to have a file extension. |
| basePath? | string|string[] |
Base path to resolve relative paths against; relative paths are rejected without it. |
Returns:
normalizedPathstring|false|nil— The normalized path, or false/nil on error.deviceOrErrstring? — The device/root component on success, or an error message on failure.dirstring? — The directory component (success only).filestring? — The file name component (success only).
getNamespacedPath ¶
Converts a base path and namespace into a namespaced filesystem path. Dots in the namespace are converted to path separators when nested is true.
| param | type | description |
|---|---|---|
| basePath | string|string[] |
Base path (or segments) the namespaced path is created under. |
| namespace | string |
|
| ext | string |
File extension (including the dot). |
| nested? | boolean |
Convert namespace dots to path separators (default true). |
Returns:
pathstring?errstring?
Fields¶
| field | type | description |
|---|---|---|
| pathSep | string |
|
| pathMatch | table |
|
| pathMaxLength | integer |
|
| pathMaxSegmentLength | integer |
|
| longPathsDisabled | string |
|
| windowsRegistryLongPathsEnabled | boolean |
Types¶
FileOpsAttributesInfo ¶
| field | type | description |
|---|---|---|
| attr | table|string|number|false |
The requested attribute(s), or false when the entry doesn't exist. |
| path | string |
The validated full path. |
| dev | string |
The device component of the path. |
| dir | string |
The directory component of the path. |
| file | string |
The file name component of the path. |