Documentation
¶
Overview ¶
Package gappdirs allows you to retrieve platform-specifc directories and files for application data, configuration, logs, and cache. This module handles platform-specific directory conventions and provides a consistent API for applications to manage their files across different operating systems. On Linux, the directory and file lookup honors the XDG Base Directory Specification v0.8 behavior.
Application files can be classified into four categories based on their purpose:
- Data - application data files that should be preserved across sessions.
- Config - configuration files that are typically looked up at the startup of the application.
- Log - files that record the state of application's execution and can be used for debugging, monitoring, or auditing purposes.
- Cache - temporary files used by the application.
Directory and file lookup of the files and directories is organized by scope:
- System - for system files that are relevant for all users. A system scope lookup will resolve to system directories only.
- User - for files that are relevant to the current user. A user scope lookup resolves to user directories first, then system directories.
- Local - for files that are in specific folders like the current directory, or a project-specific directories. Local scope resolves to local directories first, then user directories, then system directories.
Use the global functions of the module to retrieve directories and files:
package main
import (
"fmt"
appdirs "github.com/andrerfcsantos/gappdirs"
)
func main() {
// User data directories
fmt.Println(appdirs.UserDataDirs("myapp")) // returns the user data directories for "myapp" in precedence order
fmt.Println(appdirs.UserDataDir("myapp")) // returns the user data directory with most precedence for "myapp"
// System log directories
fmt.Println(appdirs.SystemLogDirs("myapp")) // returns the system log directories for "myapp" in precedence order
fmt.Println(appdirs.SystemLogDir("myapp")) // returns the system log directory with most precedence for "myapp"
// Create a config file in the directory with the most precedence for the user scope
created, configPath, err := appdirs.CreateUserConfigFile("myapp", "settings.yaml")
if err != nil {
log.Fatal(err)
}
fmt.Println("config file path:", configPath, "created:", created)
// Find all existing config files names matching "settings.yaml" in the config dirs for user scope
configFiles, err := appdirs.FindUserConfigFiles("myapp", "settings.yaml")
if err != nil {
fmt.Println("error finding config files:", err)
}
fmt.Println("config files:", configFiles)
}
If you do operations on a scope for a single app name often, you can create a Resolver for that app name and scope, and use it for operations in files and directories:
package main
import (
"fmt"
appdirs "github.com/andrerfcsantos/gappdirs"
)
func main() {
// The same example as above, but using a Resolver
// Create a resolver for the user scope for the app "myapp"
resolver := appdirs.NewUserResolver("myapp")
// User data directories
fmt.Println(resolver.DataDirs()) // returns the user data directories for "myapp" in precedence order
fmt.Println(resolver.DataDir()) // returns the user data directory with most precedence for "myapp"
// User log directories
fmt.Println(resolver.LogDirs()) // returns the user log directories for "myapp" in precedence order
fmt.Println(resolver.LogDir()) // returns the user log directory with most precedence for "myapp"
// Create a config file in the directory with the most precedence for the user scope
created, configPath, err := resolver.CreateConfigFile("settings.yaml")
if err != nil {
log.Fatal(err)
}
fmt.Println("config file path:", configPath, "created:", created)
// Find all existing config files names matching "settings.yaml" in the config dirs for user scope
configFiles, err := resolver.FindConfigFiles("settings.yaml")
if err != nil {
fmt.Println("error finding config files:", err)
}
fmt.Println("config files:", configFiles)
}
Index ¶
- Constants
- Variables
- func CreateLocalCacheFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateLocalConfigFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateLocalDataFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateLocalLogFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateSystemCacheFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateSystemConfigFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateSystemDataFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateSystemLogFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateUserCacheFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateUserConfigFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateUserDataFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func CreateUserLogFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
- func EnsureLocalCacheDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureLocalConfigDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureLocalDataDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureLocalLogDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureSystemCacheDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureSystemConfigDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureSystemDataDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureSystemLogDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureUserCacheDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureUserConfigDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureUserDataDir(appName string, opts ...EnsureOption) (string, error)
- func EnsureUserLogDir(appName string, opts ...EnsureOption) (string, error)
- func FindLocalCacheFile(appName string, filename string) (string, error)
- func FindLocalCacheFiles(appName string, filename string) ([]string, error)
- func FindLocalConfigFile(appName string, filename string) (string, error)
- func FindLocalConfigFiles(appName string, filename string) ([]string, error)
- func FindLocalDataFile(appName string, filename string) (string, error)
- func FindLocalDataFiles(appName string, filename string) ([]string, error)
- func FindLocalLogFile(appName string, filename string) (string, error)
- func FindLocalLogFiles(appName string, filename string) ([]string, error)
- func FindSystemCacheFile(appName string, filename string) (string, error)
- func FindSystemCacheFiles(appName string, filename string) ([]string, error)
- func FindSystemConfigFile(appName string, filename string) (string, error)
- func FindSystemConfigFiles(appName string, filename string) ([]string, error)
- func FindSystemDataFile(appName string, filename string) (string, error)
- func FindSystemDataFiles(appName string, filename string) ([]string, error)
- func FindSystemLogFile(appName string, filename string) (string, error)
- func FindSystemLogFiles(appName string, filename string) ([]string, error)
- func FindUserCacheFile(appName string, filename string) (string, error)
- func FindUserCacheFiles(appName string, filename string) ([]string, error)
- func FindUserConfigFile(appName string, filename string) (string, error)
- func FindUserConfigFiles(appName string, filename string) ([]string, error)
- func FindUserDataFile(appName string, filename string) (string, error)
- func FindUserDataFiles(appName string, filename string) ([]string, error)
- func FindUserLogFile(appName string, filename string) (string, error)
- func FindUserLogFiles(appName string, filename string) ([]string, error)
- func LocalCacheDir(appName string) string
- func LocalCacheDirs(appName string) []string
- func LocalCacheFilePath(appName string, filename string) string
- func LocalCacheFilePaths(appName string, filename string) []string
- func LocalConfigDir(appName string) string
- func LocalConfigDirs(appName string) []string
- func LocalConfigFilePath(appName string, filename string) string
- func LocalConfigFilePaths(appName string, filename string) []string
- func LocalDataDir(appName string) string
- func LocalDataDirs(appName string) []string
- func LocalDataFilePath(appName string, filename string) string
- func LocalDataFilePaths(appName string, filename string) []string
- func LocalLogDir(appName string) string
- func LocalLogDirs(appName string) []string
- func LocalLogFilePath(appName string, filename string) string
- func LocalLogFilePaths(appName string, filename string) []string
- func SystemCacheDir(appName string) string
- func SystemCacheDirs(appName string) []string
- func SystemCacheFilePath(appName string, filename string) string
- func SystemCacheFilePaths(appName string, filename string) []string
- func SystemConfigDir(appName string) string
- func SystemConfigDirs(appName string) []string
- func SystemConfigFilePath(appName string, filename string) string
- func SystemConfigFilePaths(appName string, filename string) []string
- func SystemDataDir(appName string) string
- func SystemDataDirs(appName string) []string
- func SystemDataFilePath(appName string, filename string) string
- func SystemDataFilePaths(appName string, filename string) []string
- func SystemLogDir(appName string) string
- func SystemLogDirs(appName string) []string
- func SystemLogFilePath(appName string, filename string) string
- func SystemLogFilePaths(appName string, filename string) []string
- func UserCacheDir(appName string) string
- func UserCacheDirs(appName string) []string
- func UserCacheFilePath(appName string, filename string) string
- func UserCacheFilePaths(appName string, filename string) []string
- func UserConfigDir(appName string) string
- func UserConfigDirs(appName string) []string
- func UserConfigFilePath(appName string, filename string) string
- func UserConfigFilePaths(appName string, filename string) []string
- func UserDataDir(appName string) string
- func UserDataDirs(appName string) []string
- func UserDataFilePath(appName string, filename string) string
- func UserDataFilePaths(appName string, filename string) []string
- func UserLogDir(appName string) string
- func UserLogDirs(appName string) []string
- func UserLogFilePath(appName string, filename string) string
- func UserLogFilePaths(appName string, filename string) []string
- type CreateFileOption
- type CreateFileOptions
- type EnsureOption
- type Resolver
- func (r *Resolver) CacheDir() string
- func (r *Resolver) CacheDirs() []string
- func (r *Resolver) CacheFilePath(filename string) string
- func (r *Resolver) CacheFilePaths(filename string) []string
- func (r *Resolver) ConfigDir() string
- func (r *Resolver) ConfigDirs() []string
- func (r *Resolver) ConfigFilePath(filename string) string
- func (r *Resolver) ConfigFilePaths(filename string) []string
- func (r *Resolver) CreateCacheFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
- func (r *Resolver) CreateConfigFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
- func (r *Resolver) CreateDataFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
- func (r *Resolver) CreateLogFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
- func (r *Resolver) DataDir() string
- func (r *Resolver) DataDirs() []string
- func (r *Resolver) DataFilePath(filename string) string
- func (r *Resolver) DataFilePaths(filename string) []string
- func (r *Resolver) EnsureCacheDir(opts ...EnsureOption) (string, error)
- func (r *Resolver) EnsureConfigDir(opts ...EnsureOption) (string, error)
- func (r *Resolver) EnsureDataDir(opts ...EnsureOption) (string, error)
- func (r *Resolver) EnsureLogDir(opts ...EnsureOption) (string, error)
- func (r *Resolver) FindCacheFile(filename string) (string, error)
- func (r *Resolver) FindCacheFiles(filename string) ([]string, error)
- func (r *Resolver) FindConfigFile(filename string) (string, error)
- func (r *Resolver) FindConfigFiles(filename string) ([]string, error)
- func (r *Resolver) FindDataFile(filename string) (string, error)
- func (r *Resolver) FindDataFiles(filename string) ([]string, error)
- func (r *Resolver) FindLogFile(filename string) (string, error)
- func (r *Resolver) FindLogFiles(filename string) ([]string, error)
- func (r *Resolver) LogDir() string
- func (r *Resolver) LogDirs() []string
- func (r *Resolver) LogFilePath(filename string) string
- func (r *Resolver) LogFilePaths(filename string) []string
- func (r *Resolver) ScopeForPath(path string) (scope Scope, found bool)
- type ResolverOption
- type Scope
Constants ¶
const DefaultCreateFilePerm fs.FileMode = 0o644
DefaultCreateFilePerm is the default file permission used for file creation operations.
const DefaultDirPerm fs.FileMode = 0o755
DefaultDirPerm is the default directory permission used for directory creation operations.
Variables ¶
var ErrNotFound = errors.New("gappdirs: no matching path found")
ErrNotFound indicates that a requested file was not found in any of the searched directories.
It is returned by all Find*File methods to allow callers to handle missing files—like falling back to defaults or creating new files—without performing string matching on errors.
Functions ¶
func CreateLocalCacheFile ¶
func CreateLocalCacheFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateLocalCacheFile creates a new file in the highest-precedence cache directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateLocalConfigFile ¶
func CreateLocalConfigFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateLocalConfigFile creates a new file in the highest-precedence config directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateLocalDataFile ¶
func CreateLocalDataFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateLocalDataFile creates a new file in the highest-precedence data directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateLocalLogFile ¶
func CreateLocalLogFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateLocalLogFile creates a new file in the highest-precedence log directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateSystemCacheFile ¶
func CreateSystemCacheFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateSystemCacheFile creates a new file in the highest-precedence cache directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateSystemConfigFile ¶
func CreateSystemConfigFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateSystemConfigFile creates a new file in the highest-precedence config directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateSystemDataFile ¶
func CreateSystemDataFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateSystemDataFile creates a new file in the highest-precedence data directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateSystemLogFile ¶
func CreateSystemLogFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateSystemLogFile creates a new file in the highest-precedence log directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateUserCacheFile ¶
func CreateUserCacheFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateUserCacheFile creates a new file in the highest-precedence cache directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateUserConfigFile ¶
func CreateUserConfigFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateUserConfigFile creates a new file in the highest-precedence config directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateUserDataFile ¶
func CreateUserDataFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateUserDataFile creates a new file in the highest-precedence data directory for appName.
It returns the absolute path to the file, and any error encountered.
func CreateUserLogFile ¶
func CreateUserLogFile(appName string, filename string, opts ...CreateFileOption) (bool, string, error)
CreateUserLogFile creates a new file in the highest-precedence log directory for appName.
It returns the absolute path to the file, and any error encountered.
func EnsureLocalCacheDir ¶
func EnsureLocalCacheDir(appName string, opts ...EnsureOption) (string, error)
EnsureLocalCacheDir ensures the existence of the highest-precedence cache directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureLocalConfigDir ¶
func EnsureLocalConfigDir(appName string, opts ...EnsureOption) (string, error)
EnsureLocalConfigDir ensures the existence of the highest-precedence config directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureLocalDataDir ¶
func EnsureLocalDataDir(appName string, opts ...EnsureOption) (string, error)
EnsureLocalDataDir ensures the highest-precedence data directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureLocalLogDir ¶
func EnsureLocalLogDir(appName string, opts ...EnsureOption) (string, error)
EnsureLocalLogDir ensures the existence of the highest-precedence log directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureSystemCacheDir ¶
func EnsureSystemCacheDir(appName string, opts ...EnsureOption) (string, error)
EnsureSystemCacheDir ensures the existence of the highest-precedence cache directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureSystemConfigDir ¶
func EnsureSystemConfigDir(appName string, opts ...EnsureOption) (string, error)
EnsureSystemConfigDir ensures the existence of the highest-precedence config directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureSystemDataDir ¶
func EnsureSystemDataDir(appName string, opts ...EnsureOption) (string, error)
EnsureSystemDataDir ensures the existence of the highest-precedence data directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureSystemLogDir ¶
func EnsureSystemLogDir(appName string, opts ...EnsureOption) (string, error)
EnsureSystemLogDir ensures the existence of the highest-precedence log directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureUserCacheDir ¶
func EnsureUserCacheDir(appName string, opts ...EnsureOption) (string, error)
EnsureUserCacheDir ensures the existence of the highest-precedence cache directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureUserConfigDir ¶
func EnsureUserConfigDir(appName string, opts ...EnsureOption) (string, error)
EnsureUserConfigDir ensures the existence of the highest-precedence config directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureUserDataDir ¶
func EnsureUserDataDir(appName string, opts ...EnsureOption) (string, error)
EnsureUserDataDir ensures the existence of the highest-precedence data directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func EnsureUserLogDir ¶
func EnsureUserLogDir(appName string, opts ...EnsureOption) (string, error)
EnsureUserLogDir ensures the existence of the highest-precedence log directory for appName and returns its path.
It returns the absolute path to the directory, and any error encountered.
func FindLocalCacheFile ¶
FindLocalCacheFile returns the first existing match for filename in cache directories for appName selected by local, user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindLocalCacheFiles ¶
FindLocalCacheFiles returns all existing matches for filename in cache directories for appName in local, user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindLocalConfigFile ¶
FindLocalConfigFile returns the first existing match for filename in config directories for appName selected by local, user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindLocalConfigFiles ¶
FindLocalConfigFiles returns all existing matches for filename in config directories for appName in local, user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindLocalDataFile ¶
FindLocalDataFile returns the first existing match for filename in data directories for appName selected by local, user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindLocalDataFiles ¶
FindLocalDataFiles returns all existing matches for filename in data directories for appName selected by local, user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindLocalLogFile ¶
FindLocalLogFile returns the first existing match for filename in log directories for appName selected by local, user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindLocalLogFiles ¶
FindLocalLogFiles returns all existing matches for filename in log directories for appName in local, user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindSystemCacheFile ¶
FindSystemCacheFile returns the first existing match for filename in cache directories for appName selected by system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindSystemCacheFiles ¶
FindSystemCacheFiles returns all existing matches for filename in cache directories for appName selected by system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindSystemConfigFile ¶
FindSystemConfigFile returns the first existing match for filename in config directories for appName selected by system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindSystemConfigFiles ¶
FindSystemConfigFiles returns all existing matches for filename in config directories for appName selected by system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindSystemDataFile ¶
FindSystemDataFile returns the first existing match for filename in data directories for appName selected by system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindSystemDataFiles ¶
FindSystemDataFiles returns all existing matches for filename in data directories for appName selected by system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindSystemLogFile ¶
FindSystemLogFile returns the first existing match for filename in log directories for appName selected by system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindSystemLogFiles ¶
FindSystemLogFiles returns all existing matches for filename in log directories for appName selected by system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindUserCacheFile ¶
FindUserCacheFile returns the first existing match for filename in cache directories for appName selected by user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindUserCacheFiles ¶
FindUserCacheFiles returns all existing matches for filename in cache directories for appName selected by user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindUserConfigFile ¶
FindUserConfigFile returns the first existing match for filename in config directories for appName selected by user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindUserConfigFiles ¶
FindUserConfigFiles returns all existing matches for filename in config directories for appName selected by user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindUserDataFile ¶
FindUserDataFile returns the first existing match for filename in data directories for appName selected by user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindUserDataFiles ¶
FindUserDataFiles returns all existing matches for filename in data directories for appName in user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func FindUserLogFile ¶
FindUserLogFile returns the first existing match for filename in log directories for appName selected by user, then system precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, it returns ErrNotFound.
func FindUserLogFiles ¶
FindUserLogFiles returns all existing matches for filename in log directories for appName selected by user, then system precedence order.
It returns the paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func LocalCacheDir ¶
LocalCacheDir returns the single highest-precedence cache directory path for appName selected by local, user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureLocalCacheDir to ensure the highest-precedence cache directory exists and get its path.
func LocalCacheDirs ¶
LocalCacheDirs returns all candidate cache directories paths, in precedence order for appName selected by local, user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureLocalCacheDir to ensure the highest-precedence cache directory exists and get its path.
func LocalCacheFilePath ¶ added in v0.2.0
LocalCacheFilePath returns the single highest-precedence cache file path for filename for appName selected by local, user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func LocalCacheFilePaths ¶ added in v0.2.0
LocalCacheFilePaths returns all candidate cache file paths for filename, in precedence order for appName selected by local, user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func LocalConfigDir ¶
LocalConfigDir returns the single highest-precedence config directory path for appName selected by local, user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureLocalConfigDir to ensure the highest-precedence config directory exists and get its path.
func LocalConfigDirs ¶
LocalConfigDirs returns all candidate config directories paths, in precedence order for appName selected by local, user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureLocalConfigDir to ensure the highest-precedence config directory exists and get its path.
func LocalConfigFilePath ¶ added in v0.2.0
LocalConfigFilePath returns the single highest-precedence config file path for filename for appName selected by local, user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func LocalConfigFilePaths ¶ added in v0.2.0
LocalConfigFilePaths returns all candidate config file paths for filename, in precedence order for appName selected by local, user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func LocalDataDir ¶
LocalDataDir returns the single highest-precedence data directory path for appName selected by local, user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureLocalDataDir to ensure the highest-precedence data directory exists and get its path.
func LocalDataDirs ¶
LocalDataDirs returns all candidate data directories paths, in precedence order for appName selected by local, user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureLocalDataDir to ensure the highest-precedence data directory exists and get its path.
func LocalDataFilePath ¶ added in v0.2.0
LocalDataFilePath returns the single highest-precedence data file path for filename for appName selected by local, user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func LocalDataFilePaths ¶ added in v0.2.0
LocalDataFilePaths returns all candidate data file paths for filename, in precedence order for appName selected by local, user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func LocalLogDir ¶
LocalLogDir returns the single highest-precedence log directory path for appName selected by local, user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureLocalLogDir to ensure the highest-precedence log directory exists and get its path.
func LocalLogDirs ¶
LocalLogDirs returns all candidate log directories paths, in precedence order for appName selected by local, user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureLocalLogDir to ensure the highest-precedence log directory exists and get its path.
func LocalLogFilePath ¶ added in v0.2.0
LocalLogFilePath returns the single highest-precedence log file path for filename for appName selected by local, user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func LocalLogFilePaths ¶ added in v0.2.0
LocalLogFilePaths returns all candidate log file paths for filename, in precedence order for appName selected by local, user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func SystemCacheDir ¶
SystemCacheDir returns the single highest-precedence cache directory path for appName selected by system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureSystemCacheDir to ensure the highest-precedence cache directory exists and get its path.
func SystemCacheDirs ¶
SystemCacheDirs returns all candidate cache directories paths, in precedence order for appName selected by system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureSystemCacheDir to ensure the highest-precedence cache directory exists and get its path.
func SystemCacheFilePath ¶ added in v0.2.0
SystemCacheFilePath returns the single highest-precedence cache file path for filename for appName selected by system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func SystemCacheFilePaths ¶ added in v0.2.0
SystemCacheFilePaths returns all candidate cache file paths for filename, in precedence order for appName selected by system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func SystemConfigDir ¶
SystemConfigDir returns the single highest-precedence config directory path for appName selected by system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureSystemConfigDir to ensure the highest-precedence config directory exists and get its path.
func SystemConfigDirs ¶
SystemConfigDirs returns all candidate config directories paths, in precedence order for appName selected by system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureSystemConfigDir to ensure the highest-precedence config directory exists and get its path.
func SystemConfigFilePath ¶ added in v0.2.0
SystemConfigFilePath returns the single highest-precedence config file path for filename for appName selected by system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func SystemConfigFilePaths ¶ added in v0.2.0
SystemConfigFilePaths returns all candidate config file paths for filename, in precedence order for appName selected by system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func SystemDataDir ¶
SystemDataDir returns the single highest-precedence data directory path for appName selected by system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureSystemDataDir to ensure the highest-precedence data directory exists and get its path.
func SystemDataDirs ¶
SystemDataDirs returns all candidate data directories paths, in precedence order for appName selected by system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureSystemDataDir to ensure the highest-precedence data directory exists and get its path.
func SystemDataFilePath ¶ added in v0.2.0
SystemDataFilePath returns the single highest-precedence data file path for filename for appName selected by system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func SystemDataFilePaths ¶ added in v0.2.0
SystemDataFilePaths returns all candidate data file paths for filename, in precedence order for appName selected by system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func SystemLogDir ¶
SystemLogDir returns the single highest-precedence log directory path for appName selected by system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureSystemLogDir to ensure the highest-precedence log directory exists and get its path.
func SystemLogDirs ¶
SystemLogDirs returns all candidate log directories paths, in precedence order for appName selected by system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureSystemLogDir to ensure the highest-precedence log directory exists and get its path.
func SystemLogFilePath ¶ added in v0.2.0
SystemLogFilePath returns the single highest-precedence log file path for filename for appName selected by system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func SystemLogFilePaths ¶ added in v0.2.0
SystemLogFilePaths returns all candidate log file paths for filename, in precedence order for appName selected by system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func UserCacheDir ¶
UserCacheDir returns the single highest-precedence cache directory path for appName selected by user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureUserCacheDir to ensure the highest-precedence cache directory exists and get its path.
func UserCacheDirs ¶
UserCacheDirs returns all candidate cache directories paths, in precedence order for appName selected by user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureUserCacheDir to ensure the highest-precedence cache directory exists and get its path.
func UserCacheFilePath ¶ added in v0.2.0
UserCacheFilePath returns the single highest-precedence cache file path for filename for appName selected by user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func UserCacheFilePaths ¶ added in v0.2.0
UserCacheFilePaths returns all candidate cache file paths for filename, in precedence order for appName selected by user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func UserConfigDir ¶
UserConfigDir returns the single highest-precedence config directory path for appName selected by user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureUserConfigDir to ensure the highest-precedence config directory exists and get its path.
func UserConfigDirs ¶
UserConfigDirs returns all candidate config directories paths, in precedence order for appName selected by user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureUserConfigDir to ensure the highest-precedence config directory exists and get its path.
func UserConfigFilePath ¶ added in v0.2.0
UserConfigFilePath returns the single highest-precedence config file path for filename for appName selected by user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func UserConfigFilePaths ¶ added in v0.2.0
UserConfigFilePaths returns all candidate config file paths for filename, in precedence order for appName selected by user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func UserDataDir ¶
UserDataDir returns the single highest-precedence data directory path for appName selected by user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureUserDataDir to ensure the highest-precedence data directory exists and get its path.
func UserDataDirs ¶
UserDataDirs returns all candidate data directories paths, in precedence order for appName selected by user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureUserDataDir to ensure the highest-precedence data directory exists and get its path.
func UserDataFilePath ¶ added in v0.2.0
UserDataFilePath returns the single highest-precedence data file path for filename for appName selected by user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func UserDataFilePaths ¶ added in v0.2.0
UserDataFilePaths returns all candidate data file paths for filename, in precedence order for appName selected by user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func UserLogDir ¶
UserLogDir returns the single highest-precedence log directory path for appName selected by user, then system precedence.
The path returned is not guaranteed to exist on the filesystem. Use EnsureUserLogDir to ensure the highest-precedence log directory exists and get its path.
func UserLogDirs ¶
UserLogDirs returns all candidate log directories paths, in precedence order for appName selected by user, then system precedence.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureUserLogDir to ensure the highest-precedence log directory exists and get its path.
func UserLogFilePath ¶ added in v0.2.0
UserLogFilePath returns the single highest-precedence log file path for filename for appName selected by user, then system precedence.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func UserLogFilePaths ¶ added in v0.2.0
UserLogFilePaths returns all candidate log file paths for filename, in precedence order for appName selected by user, then system precedence.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
Types ¶
type CreateFileOption ¶
type CreateFileOption func(*CreateFileOptions)
CreateFileOption allows setting one option on file creation operations.
func WithContentsFromReader ¶
func WithContentsFromReader(reader io.Reader) CreateFileOption
WithContentsFromReader sets the contents of the new file being created to the contents of the reader.
If this option is not set a new file will be created with no content.
func WithFilePerm ¶
func WithFilePerm(perm fs.FileMode) CreateFileOption
WithFilePerm sets the file permission used when creating new files.
If this option is not set a default permission of 0o644 is used. Invalid permissions are ignored and the default is used instead.
func WithOverwriteExisting ¶
func WithOverwriteExisting() CreateFileOption
WithOverwriteExisting allows overwriting existing files in file creation operations.
If the option WithContentsFromReader is also used, the contents of the reader will be written to the file, overwriting the existing contents.
type CreateFileOptions ¶
type CreateFileOptions struct {
// contains filtered or unexported fields
}
CreateFileOptions contains the options passed on file creation operations.
type EnsureOption ¶
type EnsureOption func(*ensureConfig)
EnsureOption configures options for directory operations. It allows adjusting directory creation details for a single directory operation.
func WithEnsureDirPerm ¶
func WithEnsureDirPerm(perm fs.FileMode) EnsureOption
WithEnsureDirPerm sets the directory permission when creating a directory.
Invalid permissions are ignored and the default is used instead.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves application directories for the current platform. It can be used for several operations of lookup and creation of application files and directories for the same scope and app name. If you just need a single operation, you might want to use the global functions of the module instead.
func NewLocalResolver ¶
func NewLocalResolver(appName string, opts ...ResolverOption) *Resolver
NewLocalResolver creates a Resolver configured to search local directories first, followed by user and then system directories.
It is typically used for development tools or applications that support project-local configuration overrides while keeping standard fallback behavior. Use the WithLocalDir or WithLocalDirs options to set the local directories.
func NewSystemResolver ¶
func NewSystemResolver(appName string, opts ...ResolverOption) *Resolver
NewSystemResolver creates a Resolver configured to search only machine-wide system directories.
It is useful for system services, daemons, or tools that manage shared assets and must intentionally ignore any user-specific or local overrides.
func NewUserResolver ¶
func NewUserResolver(appName string, opts ...ResolverOption) *Resolver
NewUserResolver creates a Resolver configured to search user directories first, followed by system directories.
It is the standard choice for most applications that store per-user configuration, data, and caches, while optionally reading machine-wide system defaults as a fallback.
func (*Resolver) CacheDir ¶
CacheDir returns the single highest-precedence cache directory path for the resolver's scope and app name.
The path returned is not guaranteed to exist on the filesystem. Use EnsureCacheDir to ensure the highest-precedence cache directory exists and get its path.
func (*Resolver) CacheDirs ¶
CacheDirs returns all candidate cache directories paths, in precedence order for the resolver's scope and app name.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureCacheDir to ensure the highest-precedence cache directory exists and get its path.
func (*Resolver) CacheFilePath ¶ added in v0.2.0
CacheFilePath returns the single highest-precedence cache file path for filename for the resolver's scope and app name.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func (*Resolver) CacheFilePaths ¶ added in v0.2.0
CacheFilePaths returns all candidate cache file paths for filename, in precedence order for the resolver's scope and app name.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func (*Resolver) ConfigDir ¶
ConfigDir returns the single highest-precedence config directory path for the resolver's scope and app name.
The path returned is not guaranteed to exist on the filesystem. Use EnsureConfigDir to ensure the highest-precedence config directory exists and get its path.
func (*Resolver) ConfigDirs ¶
ConfigDirs returns all candidate config directories paths, in precedence order for the resolver's scope and app name.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureConfigDir to ensure the highest-precedence config directory exists and get its path.
func (*Resolver) ConfigFilePath ¶ added in v0.2.0
ConfigFilePath returns the single highest-precedence config file path for filename for the resolver's scope and app name.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func (*Resolver) ConfigFilePaths ¶ added in v0.2.0
ConfigFilePaths returns all candidate config file paths for filename, in precedence order for the resolver's scope and app name.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func (*Resolver) CreateCacheFile ¶
func (r *Resolver) CreateCacheFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
CreateCacheFile creates a file with the given name in the highest-precedence cache directory for the Resolver scope.
If the file already exists, it will not be modified, unless the WithOverwriteExisting option is used. If the file does not exist, it will be created with the specified permissions and contents (if provided).
It returns a boolean indicating whether a new file was created and didn't exist before, the absolute path to the file, and any error encountered.
func (*Resolver) CreateConfigFile ¶
func (r *Resolver) CreateConfigFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
CreateConfigFile creates a file with the given name in the highest-precedence config directory for the Resolver scope.
If the file already exists, it will not be modified, unless the WithOverwriteExisting option is used. If the file does not exist, it will be created with the specified permissions and contents (if provided).
It returns a boolean indicating whether a new file was created and didn't exist before, the absolute path to the file, and any error encountered.
func (*Resolver) CreateDataFile ¶
func (r *Resolver) CreateDataFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
CreateDataFile creates a file with the given name in the highest-precedence data directory for the Resolver scope.
If the file already exists, it will not be modified, unless the WithOverwriteExisting option is used. If the file does not exist, it will be created with the specified permissions and contents (if provided).
It returns a boolean indicating whether a new file was created and didn't exist before, the absolute path to the file, and any error encountered.
func (*Resolver) CreateLogFile ¶
func (r *Resolver) CreateLogFile(filename string, opts ...CreateFileOption) (created bool, path string, err error)
CreateLogFile creates a file with the given name in the highest-precedence log directory for the Resolver scope.
If the file already exists, it will not be modified, unless the WithOverwriteExisting option is used. If the file does not exist, it will be created with the specified permissions and contents (if provided).
It returns a boolean indicating whether a new file was created and didn't exist before, the absolute path to the file, and any error encountered.
func (*Resolver) DataDir ¶
DataDir returns the single highest-precedence data directory path for the resolver's scope and app name.
The path returned is not guaranteed to exist on the filesystem. Use EnsureDataDir to ensure the highest-precedence data directory exists and get its path.
func (*Resolver) DataDirs ¶
DataDirs returns all candidate data directories paths, in precedence order for the resolver's scope and app name.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureDataDir to ensure the highest-precedence data directory exists and get its path.
func (*Resolver) DataFilePath ¶ added in v0.2.0
DataFilePath returns the single highest-precedence data file path for filename for the resolver's scope and app name.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func (*Resolver) DataFilePaths ¶ added in v0.2.0
DataFilePaths returns all candidate data file paths for filename, in precedence order for the resolver's scope and app name.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func (*Resolver) EnsureCacheDir ¶
func (r *Resolver) EnsureCacheDir(opts ...EnsureOption) (string, error)
EnsureCacheDir ensures the existence of the highest-precedence cache directory for the Resolver scope by creating it if it doesn't exist.
It returns the absolute path to the directory, and any error encountered.
func (*Resolver) EnsureConfigDir ¶
func (r *Resolver) EnsureConfigDir(opts ...EnsureOption) (string, error)
EnsureConfigDir ensures the existence of the highest-precedence config directory for the Resolver scope by creating it if it doesn't exist.
It returns the absolute path to the directory, and any error encountered.
func (*Resolver) EnsureDataDir ¶
func (r *Resolver) EnsureDataDir(opts ...EnsureOption) (string, error)
EnsureDataDir ensures the existence of the highest-precedence data directory for the Resolver scope by creating it if it doesn't exist.
It returns the absolute path to the directory, and any error encountered.
func (*Resolver) EnsureLogDir ¶
func (r *Resolver) EnsureLogDir(opts ...EnsureOption) (string, error)
EnsureLogDir ensures the existence of the highest-precedence log directory for the Resolver scope by creating it if it doesn't exist.
It returns the absolute path to the directory, and any error encountered.
func (*Resolver) FindCacheFile ¶
FindCacheFile returns the first existing match for filename in cache directories by precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, an error of type ErrNotFound is returned.
func (*Resolver) FindCacheFiles ¶
FindCacheFiles returns all existing matches for filename in cache directories by precedence order.
It returns thr paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func (*Resolver) FindConfigFile ¶
FindConfigFile returns the first existing match for filename in config directories by precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, an error of type ErrNotFound is returned.
func (*Resolver) FindConfigFiles ¶
FindConfigFiles returns all existing matches for filename in config directories by precedence order.
It returns thr paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func (*Resolver) FindDataFile ¶
FindDataFile returns the first existing match for filename in data directories by precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, an error of type ErrNotFound is returned.
func (*Resolver) FindDataFiles ¶
FindDataFiles returns all existing matches for filename in data directories by precedence order.
It returns thr paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func (*Resolver) FindLogFile ¶
FindLogFile returns the first existing match for filename in log directories by precedence.
It returns the path to the existing file and any error encountered during the lookup. If no matching file is found, an error of type ErrNotFound is returned.
func (*Resolver) FindLogFiles ¶
FindLogFiles returns all existing matches for filename in log directories by precedence order.
It returns thr paths to the existing files and any error encountered during the lookup. If no matching files are found, it returns an empty slice and nil error.
func (*Resolver) LogDir ¶
LogDir returns the single highest-precedence log directory path for the resolver's scope and app name.
The path returned is not guaranteed to exist on the filesystem. Use EnsureLogDir to ensure the highest-precedence log directory exists and get its path.
func (*Resolver) LogDirs ¶
LogDirs returns all candidate log directories paths, in precedence order for the resolver's scope and app name.
The paths returned are not guaranteed to exist on the filesystem. Use EnsureLogDir to ensure the highest-precedence log directory exists and get its path.
func (*Resolver) LogFilePath ¶ added in v0.2.0
LogFilePath returns the single highest-precedence log file path for filename for the resolver's scope and app name.
The path returned is a computed candidate and is not guaranteed to exist on the filesystem.
func (*Resolver) LogFilePaths ¶ added in v0.2.0
LogFilePaths returns all candidate log file paths for filename, in precedence order for the resolver's scope and app name.
The paths returned are computed candidates and are not guaranteed to exist on the filesystem.
func (*Resolver) ScopeForPath ¶ added in v0.3.0
ScopeForPath returns the matching scope for path for the Resolver app name and scope.
It checks only the scope layers available for the resolver:
- local resolvers check local, user, then system
- user resolvers check user then system
- system resolvers check system only
The path does not need to exist on disk.
type ResolverOption ¶
type ResolverOption func(*newResolverConfig)
ResolverOption sets an option when creating a resolver. It allows adjusting the local directories and the default directory permissions of a resolver.
func WithDefaultDirPerm ¶
func WithDefaultDirPerm(perm fs.FileMode) ResolverOption
WithDefaultDirPerm sets the default permission used when creating a directory.
Invalid permissions are ignored and the default is used instead.
func WithLocalDir ¶
func WithLocalDir(dir string) ResolverOption
WithLocalDir sets a local working directory root used for local scope.
This option can be used multiple times to set multiple local directories. Directories given first have highest precedence. Duplicate directories are ignored and only the first occurrence is used.
func WithLocalDirs ¶
func WithLocalDirs(dirs ...string) ResolverOption
WithLocalDirs sets one or multiple local working directory roots used for local scope.
Directories given first have highest precedence. Duplicate directories are ignored and only the first occurrence is used.
type Scope ¶
type Scope int
Scope determines which directory layers are searched for each lookup.
It allows callers to control the level of visibility and persistence for their files, choosing between project-local, per-user, or machine-wide system directories.
const ( // ScopeLocal includes the current working directory as the highest priority, // falling back to user directories, and then system directories. ScopeLocal Scope = iota // ScopeUser includes user-specific directories as the highest priority, // falling back to system directories. ScopeUser // ScopeSystem includes only machine-wide system directories, ignoring user // and local paths. ScopeSystem )
func ScopeForPath ¶ added in v0.3.0
ScopeForPath returns the matching scope for path for app name and a bool indicating if a match was found.
Directory comparison and lookup checks path candidates in local, then user, then system precedence. In other words, it assumes local scope for directory comparison.
The path does not need to exist on disk.