☰

# std/private/osappdirs

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

# Imports

envvars, ospaths2

# Procs

    proc getCacheDir(): string {....raises: [], tags: [ReadEnvEffect], forbids: [].}

  Returns the cache directory of the current user for applications.

  This makes use of the following environment variables:

  - On Windows: `getEnv("LOCALAPPDATA")`
  - On macOS: `getEnv("XDG_CACHE_HOME", getEnv("HOME") / "Library/Caches")`
  - On other platforms: `getEnv("XDG_CACHE_HOME", getEnv("HOME") / ".cache")`

  See also:

  - getHomeDir proc
  - getTempDir proc
  - getConfigDir proc
  - getDataDir proc
  Source Edit

    proc getCacheDir(app: string): string {....raises: [], tags: [ReadEnvEffect],
                                            forbids: [].}

  Returns the cache directory for an application `app`.
  - On Windows, this uses: `getCacheDir() / app / "cache"`
  - On other platforms, this uses: `getCacheDir() / app`
  Source Edit

    proc getConfigDir(): string {....gcsafe, extern: "nos$1",
                                  tags: [ReadEnvEffect, ReadIOEffect], raises: [],
                                  forbids: [].}

  Returns the config directory of the current user for applications.

  On non-Windows OSs, this proc conforms to the XDG Base Directory spec. Thus, this proc returns the value of the `XDG_CONFIG_HOME` environment variable if it is set, otherwise it returns the default configuration directory ("~/.config/").

  An OS-dependent trailing slash is always present at the end of the returned string: `\\` on Windows and `/` on all other OSs.

  See also:

  - getHomeDir proc
  - getDataDir proc
  - getTempDir proc
  - paths: expandTilde proc
  - paths: getCurrentDir proc
  - dirs: setCurrentDir proc
  Source Edit

    proc getDataDir(): string {....gcsafe, extern: "nos$1",
                                tags: [ReadEnvEffect, ReadIOEffect], raises: [],
                                forbids: [].}

  Returns the data directory of the current user for applications.

  On non-Windows OSs, this proc conforms to the XDG Base Directory spec. Thus, this proc returns the value of the `XDG_DATA_HOME` environment variable if it is set, otherwise it returns the default configuration directory ("~/.local/share" or "~/Library/Application Support" on macOS).

  See also:

  - getHomeDir proc
  - getConfigDir proc
  - getTempDir proc
  - paths: expandTilde proc
  - paths: getCurrentDir proc
  - dirs: setCurrentDir proc
  Source Edit

    proc getHomeDir(): string {....gcsafe, extern: "nos$1",
                                tags: [ReadEnvEffect, ReadIOEffect], raises: [],
                                forbids: [].}

  Returns the home directory of the current user.

  This proc is wrapped by the paths: expandTilde proc for the convenience of processing paths coming from user configuration files.

  See also:

  - getDataDir proc
  - getConfigDir proc
  - getTempDir proc
  - paths: expandTilde proc
  - paths: getCurrentDir proc
  - dirs: setCurrentDir proc

  Example:

      import std/os
      assert getHomeDir() == expandTilde("~")

  Source Edit

    proc getTempDir(): string {....gcsafe, extern: "nos$1",
                                tags: [ReadEnvEffect, ReadIOEffect], raises: [],
                                forbids: [].}

  Returns the temporary directory of the current user for applications to save temporary files in.

  On Windows, it calls GetTempPath. On Posix based platforms, it will check `TMPDIR`, `TEMP`, `TMP` and `TEMPDIR` environment variables in order. On all platforms, `/tmp` will be returned if the procs fails.

  You can override this implementation by adding `-d:tempDir=mytempname` to your compiler invocation.

  Note: This proc does not check whether the returned path exists.

  See also:

  - getHomeDir proc
  - getConfigDir proc
  - paths: expandTilde proc
  - paths: getCurrentDir proc
  - dirs: setCurrentDir proc
  Source Edit