Methods
-
exec(command, params, env){Promise.<LuCI.fs.FileExecResult>}
-
Execute the specified command, optionally passing params and environment variables.
Note: The
commandmust 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 inparamswill be passed as arguments to the command.The key/value pairs in the optional
envtable are translated tosetenv()calls prior to running the command.Name Type Description commandstring The command to invoke.
paramsArray.<string> optional The arguments to pass to the command.
envObject.<string, string> optional Environment variables to set.
Returns:
Type Description Promise.<LuCI.fs.FileExecResult> Returns a promise resolving to an object describing the execution results or rejecting with an error stating the failure reason. -
Execute the specified command, bypassing ubus.
Note: The
commandmust 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 inparamswill be passed as arguments to the command.This function will invoke the requested commands through the cgi-io helper applet at
/cgi-bin/cgi-execwhich 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 Default Description commandstring The command to invoke.
paramsArray.<string> optional The arguments to pass to the command.
type"blob" | "text" | "json" text optional The expected output type of the invoked program. Valid values are
textto interpret the output as string,jsonto parse the output as JSON orblobto return the output as Blob instance.latin1boolean false optional 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.
Returns:
Type Description Promise.<*> Returns a promise resolving with the command stdout output interpreted according to the specified type or rejecting with an error stating the failure reason. -
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 pathstring The file path to read.
Returns:
Type Description Promise.<Array.<string>> Returns a promise resolving to an array containing the stripped lines of the given file or []on failure. -
list(path){Promise.<Array.<LuCI.fs.FileStatEntry>>}
-
Obtains a listing of the specified directory.
Name Type Description pathstring The directory path to list.
Returns:
Type Description Promise.<Array.<LuCI.fs.FileStatEntry>> Returns a promise resolving to an array of stat detail objects or rejecting with an error stating the failure reason. -
Read the contents of the given file and return them. Note: this function is unsuitable for obtaining binary data.
Name Type Description pathstring The file path to read.
Returns:
Type Description Promise.<string> Returns a promise resolving to a string containing the file contents or rejecting with an error stating the failure reason. -
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-downloadwhich 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 Default Description pathstring The file path to read.
type"blob" | "text" | "json" text optional The expected type of read file contents. Valid values are
textto interpret the contents as string,jsonto parse the contents as JSON orblobto return the contents as Blob instance.Returns:
Type Description Promise.<*> Returns a promise resolving with the file contents interpreted according to the specified type or rejecting with an error stating the failure reason. -
Unlink the given file.
Name Type Description pathstring The file path to remove.
Returns:
Type Description Promise.<number> Returns a promise resolving to 0or rejecting with an error stating the failure reason. -
stat(path){Promise.<LuCI.fs.FileStatEntry>}
-
Return file stat information on the specified path.
Name Type Description pathstring The filesystem path to stat.
Returns:
Type Description Promise.<LuCI.fs.FileStatEntry> Returns a promise resolving to a stat detail object or rejecting with an error stating the failure reason. -
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
/sysor/proc.This function is guaranteed to not reject its promises, on failure, an empty string will be returned.
Name Type Description pathstring The file path to read.
Returns:
Type Description Promise.<string> Returns a promise resolving to the file contents or the empty string on failure. -
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:
datawill be converted to a string usingString(data)or to''when it isnull.Name Type Description pathstring 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.
modenumber optional The permissions to use on file creation. Default is 420 (0644).
Returns:
Type Description Promise.<number> Returns a promise resolving to 0or rejecting with an error stating the failure reason.
Type Definitions
-
LuCI.fs.FileExecResultObject
-
Properties:
Name Type Argument Description codenumber The exit code of the invoked command
stdoutstring <optional>
The stdout produced by the command, if any
stderrstring <optional>
The stderr produced by the command, if any
-
LuCI.fs.FileStatEntryObject
-
Properties:
Name Type Description namestring Name of the directory entry
typestring Type of the entry, one of
block,char,directory,fifo,symlink,file,socketorunknownsizenumber Size in bytes
modenumber Access permissions
atimenumber Last access time in seconds since epoch
mtimenumber Last modification time in seconds since epoch
ctimenumber Last change time in seconds since epoch
inodenumber Inode number
uidnumber Numeric owner id
gidnumber Numeric group id