Methods
exec(command, paramsopt, envopt) → {Promise.<LuCI.fs.FileExecResult>}
Execute the specified command, optionally passing params and environment variables.
Note: The command must be either the path to an executable, or a basename without arguments in which case it will be searched in $PATH. If specified, the values given in params will be passed as arguments to the command.
The key/value pairs in the optional env table are translated to setenv() calls prior to running the command.
| Name | Type | Attributes | Description |
|---|---|---|---|
command | string | The command to invoke. | |
params | Array.<string> | <optional> | The arguments to pass to the command. |
env | Object.<string, string> | <optional> | Environment variables to set. |
Returns a promise resolving to an object describing the execution results or rejecting with an error stating the failure reason.
- Type:
- Promise.<LuCI.fs.FileExecResult>
exec_direct(command, paramsopt, typeopt, latin1opt, stderropt, responseProgressopt) → {Promise.<*>}
Execute the specified command, bypassing ubus.
Note: The command must be either the path to an executable, or a basename without arguments in which case it will be searched in $PATH. If specified, the values given in params will be passed as arguments to the command.
This function will invoke the requested commands through the cgi-io helper applet at /cgi-bin/cgi-exec which bypasses the ubus rpc transport. This is useful to fetch large command outputs which might exceed the ubus message size limits or which contain binary data.
The cgi-io helper will enforce the same access permission rules as the ubus based exec call.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
command | string | The command to invoke. | ||
params | Array.<string> | <optional> | The arguments to pass to the command. | |
type | "blob" | | <optional> | text | The expected output type of the invoked program. Valid values are |
latin1 | boolean | <optional> | false | Whether to encode the command line as Latin1 instead of UTF-8. This is usually not needed but can be useful for programs that cannot handle UTF-8 input. |
stderr | boolean | <optional> | false | Whether to include stderr output in command output. This is usually not needed but can be useful to execute a command and get full output. |
responseProgress | function | <optional> | null | An optional request callback function which receives ProgressEvent instances as sole argument during the HTTP response transfer. This is usually not needed but can be useful to receive realtime command output before command exit. |
Returns a promise resolving with the command stdout output interpreted according to the specified type or rejecting with an error stating the failure reason.
- Type:
- Promise.<*>
lines(path) → {Promise.<Array.<string>>}
Read the contents of the given file, split it into lines, trim leading and trailing white space of each line and return the resulting array.
This function is guaranteed to not reject its promises, on failure, an empty array will be returned.
| Name | Type | Description |
|---|---|---|
path | string | The file path to read. |
Returns a promise resolving to an array containing the stripped lines of the given file or [] on failure.
- Type:
- Promise.<Array.<string>>
list(path) → {Promise.<Array.<LuCI.fs.FileStatEntry>>}
Obtains a listing of the specified directory.
| Name | Type | Description |
|---|---|---|
path | string | The directory path to list. |
Returns a promise resolving to an array of stat detail objects or rejecting with an error stating the failure reason.
- Type:
- Promise.<Array.<LuCI.fs.FileStatEntry>>
read(path) → {Promise.<string>}
Read the contents of the given file and return them. Note: this function is unsuitable for obtaining binary data.
| Name | Type | Description |
|---|---|---|
path | string | The file path to read. |
Returns a promise resolving to a string containing the file contents or rejecting with an error stating the failure reason.
- Type:
- Promise.<string>
read_direct(path, typeopt) → {Promise.<*>}
Read the contents of the given file and return them, bypassing ubus.
This function will read the requested file through the cgi-io helper applet at /cgi-bin/cgi-download which bypasses the ubus rpc transport. This is useful to fetch large file contents which might exceed the ubus message size limits or which contain binary data.
The cgi-io helper will enforce the same access permission rules as the ubus based read call.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
path | string | The file path to read. | ||
type | "blob" | | <optional> | text | The expected type of read file contents. Valid values are |
Returns a promise resolving with the file contents interpreted according to the specified type or rejecting with an error stating the failure reason.
- Type:
- Promise.<*>
remove(path) → {Promise.<number>}
Unlink the given file.
| Name | Type | Description |
|---|---|---|
path | string | The file path to remove. |
Returns a promise resolving to 0 or rejecting with an error stating the failure reason.
- Type:
- Promise.<number>
stat(path) → {Promise.<LuCI.fs.FileStatEntry>}
Return file stat information on the specified path.
| Name | Type | Description |
|---|---|---|
path | string | The filesystem path to stat. |
Returns a promise resolving to a stat detail object or rejecting with an error stating the failure reason.
- Type:
- Promise.<LuCI.fs.FileStatEntry>
trimmed(path) → {Promise.<string>}
Read the contents of the given file, trim leading and trailing white space and return the trimmed result. In case of errors, return an empty string instead.
Note: this function is useful to read single-value files in /sys or /proc.
This function is guaranteed to not reject its promises, on failure, an empty string will be returned.
| Name | Type | Description |
|---|---|---|
path | string | The file path to read. |
Returns a promise resolving to the file contents or the empty string on failure.
- Type:
- Promise.<string>
write(path, dataopt, modeopt) → {Promise.<number>}
Write the given data to the specified file path. If the specified file path does not exist, it will be created, given sufficient permissions.
Note: data will be converted to a string using String(data) or to '' when it is null.
| Name | Type | Attributes | Description |
|---|---|---|---|
path | string | The file path to write to. | |
data | * | <optional> | The file data to write. If it is null, it will be set to an empty string. |
mode | number | <optional> | The permissions to use on file creation. Default is 420 (0644). |
Returns a promise resolving to 0 or rejecting with an error stating the failure reason.
- Type:
- Promise.<number>
Type Definitions
FileExecResult
- Object
| Name | Type | Attributes | Description |
|---|---|---|---|
code | number | The exit code of the invoked command | |
stdout | string | <optional> | The stdout produced by the command, if any |
stderr | string | <optional> | The stderr produced by the command, if any |
FileStatEntry
- Object
| Name | Type | Description |
|---|---|---|
name | string | Name of the directory entry |
type | string | Type of the entry, one of |
size | number | Size in bytes |
mode | number | Access permissions |
atime | number | Last access time in seconds since epoch |
mtime | number | Last modification time in seconds since epoch |
ctime | number | Last change time in seconds since epoch |
inode | number | Inode number |
uid | number | Numeric owner id |
gid | number | Numeric group id |