### Directory Creation and Permissions Source: https://specifications.freedesktop.org/basedir-spec/latest/index When writing files, applications should attempt to create non-existent destination directories with 0700 permissions. Existing directory permissions should not be altered. Applications must handle potential write failures gracefully. ```shell # Attempt to create directory if it doesn't exist mkdir -p --mode=0700 /path/to/destination/directory # Write file (handle potential errors) if ! echo "content" > /path/to/destination/directory/file.txt; then echo "Error: Could not write file." fi ``` -------------------------------- ### XDG Search Path Environment Variables Source: https://specifications.freedesktop.org/basedir-spec/latest/index Defines preference-ordered directories for searching data and configuration files, in addition to the HOME variables. Uses platform-specific path separators. ```APIDOC XDG_DATA_DIRS: Preference-ordered set of base directories to search for data files. Directories are separated by the platform's PATH separator (e.g., ':'). Default: /usr/local/share/:/usr/share/ XDG_CONFIG_DIRS: Preference-ordered set of base directories to search for configuration files. Directories are separated by the platform's PATH separator (e.g., ':'). Default: /etc/xdg Priority: - Directories in XDG_DATA_DIRS are searched after XDG_DATA_HOME. - Directories in XDG_CONFIG_DIRS are searched after XDG_CONFIG_HOME. - Earlier directories in the lists have higher precedence. ``` -------------------------------- ### Environment Variable Usage in Applications Source: https://specifications.freedesktop.org/basedir-spec/latest/index Applications should reference user-specific data and configuration files using environment variables like $XDG_DATA_HOME and $XDG_CONFIG_HOME. If these variables are not set, default paths are used. This ensures a consistent file structure across different user environments. ```shell # Referencing data files $XDG_DATA_DIRS/subdir/filename # Referencing configuration files $XDG_CONFIG_DIRS/subdir/filename # Fallback for runtime directory $XDG_RUNTIME_DIR ``` -------------------------------- ### User-Specific Executable Files Source: https://specifications.freedesktop.org/basedir-spec/latest/index Specifies the location for user-specific executable files and considerations for cross-architecture compatibility. ```APIDOC User Executable Directory: Location: $HOME/.local/bin Recommendation: Distributions should ensure this directory is in the system's $PATH. Consideration: Placing compiled binaries here can cause issues if $HOME is shared across different architectures. ``` -------------------------------- ### XDG Base Directory Environment Variables Source: https://specifications.freedesktop.org/basedir-spec/latest/index Defines the primary environment variables for user-specific data, configuration, and state. Includes default values if variables are not set or empty. ```APIDOC XDG_DATA_HOME: Defines the base directory for user-specific data files. Default: $HOME/.local/share XDG_CONFIG_HOME: Defines the base directory for user-specific configuration files. Default: $HOME/.config XDG_STATE_HOME: Defines the base directory for user-specific state files (e.g., action history, application state). Default: $HOME/.local/state XDG_CACHE_HOME: Defines the base directory for user-specific non-essential data files. Default: $HOME/.cache XDG_RUNTIME_DIR: Defines the base directory for user-specific non-essential runtime files and objects (sockets, pipes). Properties: - Must be owned by the user with read/write access only (0700). - Lifetime bound to user login session; removed on logout. - Must not survive reboots or full logout/login cycles. - Must be on a local filesystem. - Must support AF_UNIX sockets, symbolic links, hard links, proper permissions, file locking, sparse files, memory mapping, file change notifications, reliable hard link count, and no filename character set restrictions. - Files may be cleaned up; update access time (every 6 hours monotonic) or set sticky bit to prevent removal. ``` -------------------------------- ### XDG Base Directory Environment Variables Source: https://specifications.freedesktop.org/basedir-spec/latest/index Defines the environment variables used to specify base directories for user-specific files. These variables dictate where applications should read from and write to for data, configuration, state, cache, and runtime files. ```APIDOC APIDOC: XDG_DATA_HOME: Description: Defines the base directory for user-specific data files. Defaults to '~/.local/share' if not set. Type: String (absolute path) XDG_CONFIG_HOME: Description: Defines the base directory for user-specific configuration files. Defaults to '~/.config' if not set. Type: String (absolute path) XDG_STATE_HOME: Description: Defines the base directory for user-specific state data. Defaults to '~/.local/state' if not set. Type: String (absolute path) XDG_DATA_DIRS: Description: Defines a preference-ordered set of base directories for user-specific data files. Defaults to '/usr/local/share/:/usr/share/'. Type: List of Strings (absolute paths) XDG_CONFIG_DIRS: Description: Defines a preference-ordered set of base directories for user-specific configuration files. Defaults to '/etc/xdg'. Type: List of Strings (absolute paths) XDG_CACHE_HOME: Description: Defines the base directory for user-specific non-essential (cached) data. Defaults to '~/.cache' if not set. Type: String (absolute path) XDG_RUNTIME_DIR: Description: Defines the base directory for user-specific runtime files and other file objects. Must be an absolute path and is typically created by systemd. Type: String (absolute path) Validation: - All paths set in these environment variables must be absolute. - Relative paths should be considered invalid and ignored. ``` -------------------------------- ### File Access Error Handling Source: https://specifications.freedesktop.org/basedir-spec/latest/index When reading files, applications should skip directories where files are inaccessible (e.g., non-existent directories, permission issues). If a required file cannot be found after skipping, an error message may be presented to the user. ```shell # Example of skipping inaccessible files (conceptual) for dir in $XDG_DATA_DIRS; do if [ -r "$dir/subdir/filename" ]; then # Process file cat "$dir/subdir/filename" break # Found and processed, exit loop fi done # If file not found after loop, handle error ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.