Function xdgCacheHome
The base directory relative to which user-specific non-essential files should be stored.
string xdgCacheHome
(
string subfolder = null,
bool shouldCreate = false
) nothrow @trusted;
Returns
Path to user-specific cache directory or empty string on error.
Parameters
Name | Description |
---|---|
subfolder | Subfolder to append to determined path. |
shouldCreate | If path does not exist, create directory using 700 permissions (i.e. allow access only for current user). |
Example
auto dataDirsGuard = EnvGuard("XDG_DATA_DIRS", "/usr/local/data:/usr/data:/usr/local/data/:/usr/data/");
auto newDataDirs = ["/usr/local/data", "/usr/data"];
assert(xdgDataDirs() == newDataDirs);
assert(equal(xdgDataDirs("applications"), newDataDirs .map!(p => buildPath(p, "applications"))));
environment .remove("XDG_DATA_DIRS");
assert(xdgDataDirs() == ["/usr/local/share", "/usr/share"]);
assert(equal(xdgDataDirs("icons"), ["/usr/local/share", "/usr/share"] .map!(p => buildPath(p, "icons"))));
Example
auto newDataHome = "/home/myuser/data";
auto newDataDirs = ["/usr/local/data", "/usr/data"];
auto homeGuard = EnvGuard("HOME", "");
auto dataHomeGuard = EnvGuard("XDG_DATA_HOME", newDataHome);
auto dataDirsGuard = EnvGuard("XDG_DATA_DIRS", "/usr/local/data:/usr/data");
assert(xdgAllDataDirs() == newDataHome ~ newDataDirs);
environment .remove("XDG_DATA_HOME");
environment .remove("HOME");
assert(xdgAllDataDirs() == newDataDirs);
Example
auto dataConfigGuard = EnvGuard("XDG_CONFIG_DIRS", "/usr/local/config:/usr/config");
auto newConfigDirs = ["/usr/local/config", "/usr/config"];
assert(xdgConfigDirs() == newConfigDirs);
assert(equal(xdgConfigDirs("menus"), newConfigDirs .map!(p => buildPath(p, "menus"))));
environment .remove("XDG_CONFIG_DIRS");
assert(xdgConfigDirs() == ["/etc/xdg"]);
assert(equal(xdgConfigDirs("autostart"), ["/etc/xdg"] .map!(p => buildPath(p, "autostart"))));
Example
auto newConfigHome = "/home/myuser/data";
auto newConfigDirs = ["/usr/local/data", "/usr/data"];
auto homeGuard = EnvGuard("HOME", "");
auto configHomeGuard = EnvGuard("XDG_CONFIG_HOME", newConfigHome);
auto configDirsGuard = EnvGuard("XDG_CONFIG_DIRS", "/usr/local/data:/usr/data");
assert(xdgAllConfigDirs() == newConfigHome ~ newConfigDirs);
environment .remove("XDG_CONFIG_HOME");
environment .remove("HOME");
assert(xdgAllConfigDirs() == newConfigDirs);