Module ztcl::appdata
ztcl::appdata gives the data folder of an app for the user: the folder where a program keeps the data of that user. It needs the capability file, as file home does, and no env capability. It reads the variables of the process itself, and it does not make the array env visible to the script.
ztcl::appdata gives a folder of the system on Linux, macOS, and Windows. On another system, host mode gives TCL VALUE PATH HOMELESS.
puts [ztcl::appdata cardbox]
/.local/share/cardbox
Synopsis
ztcl::appdata NAME
NAME is the name of the app, one path element. The command exists when the embedder turns on file. The ztcl program turns it on with --allow file. The command gives the path of the folder and does not make the folder: a program makes it with file mkdir when it needs it.
The folder
With a root folder (--root DIR, or fsroot.setRoot in Zig), the folder is /.local/share/NAME inside the root, the same on each system. file home gives / there.
In host mode (fsroot.setHost in Zig, or no --root in the ztcl program), the folder follows the system:
| System | The folder of NAME |
|---|---|
| Linux | $XDG_DATA_HOME/NAME when XDG_DATA_HOME is set and not empty, else $HOME/.local/share/NAME |
| macOS | $HOME/Library/Application Support/NAME |
| Windows | %APPDATA%\NAME when APPDATA is set and not empty, else $HOME\AppData\Roaming\NAME |
An empty variable counts as absent. With no HOME (and no APPDATA on Windows), the command gives TCL VALUE PATH HOMELESS, as file home does.
NAME
NAME is one path element: it is not empty, has no / and no \, and is not . or ... Another name gives TCL VALUE PATH NAME.
Errors
| Error code | Message | Cause |
|---|---|---|
TCL WRONGARGS |
wrong # args: should be "ztcl::appdata name" |
The command got no name, or more than one. |
TCL VALUE PATH NAME |
bad name "NAME": must be one path element |
NAME is empty, is . or .., or has a slash. |
TCL VALUE PATH HOMELESS |
couldn't find HOME environment variable to expand path |
Host mode has no HOME (and no APPDATA on Windows). |
puts [catch {ztcl::appdata a/b} m o]
puts $m
puts [dict get $o -errorcode]
1
bad name "a/b": must be one path element
TCL VALUE PATH NAME
Platforms
- Linux:
$XDG_DATA_HOME, else$HOME/.local/share, in host mode, and/.local/sharein a root folder. - macOS:
$HOME/Library/Application Supportin host mode, and/.local/sharein a root folder. - Windows:
%APPDATA%, else$HOME\AppData\Roaming, in host mode, and/.local/sharein a root folder. - WebAssembly and WASI:
/.local/sharein a root folder. Host mode has no environment of the process.