Documentation
¶
Overview ¶
Package appdata resolves where the application keeps its per-user data: the SQLite database, the copies of the prompt library and the launch defaults kept beside it, generated launch scripts, and logs. It also writes and reads those files, readable only by the user.
The location follows each operating system's convention. The resolver itself is a pure function of the OS name, the home directory, and the environment, so every branch is testable on any host even though only macOS is supported at run time today.
Index ¶
Constants ¶
const ( // PrivateDirPerm is the mode of every directory the application creates. PrivateDirPerm fs.FileMode = 0o700 // PrivateFilePerm is the mode of every file the application writes. PrivateFilePerm fs.FileMode = 0o600 )
Permissions for everything the application writes: its data is private to the user.
Variables ¶
var ( // ErrUnsupportedOS is returned for an operating system with no known data location. ErrUnsupportedOS = errors.New("unsupported operating system") // ErrNoHomeDir is returned when the home directory is needed but empty. ErrNoHomeDir = errors.New("home directory is not set") // ErrNoAppDataEnv is returned on Windows when %AppData% is not set. ErrNoAppDataEnv = errors.New("APPDATA environment variable is not set") )
var ( // ErrTooLarge is returned by ReadFile for a file larger than the limit it was given. ErrTooLarge = errors.New("the file is too large") // ErrNotAFile is returned by ReadFile for a path that is not a regular file. ErrNotAFile = errors.New("not a file") )
Functions ¶
func Dir ¶
Dir returns the per-user data directory for the given OS, home directory, and environment lookup:
- darwin: <home>/Library/Application Support/<DataDirName>
- linux: $XDG_DATA_HOME/<Slug>, else <home>/.local/share/<Slug>
- windows: %AppData%/<DataDirName>
Any other OS returns ErrUnsupportedOS.
func ReadFile ¶ added in v0.2.0
ReadFile reads the regular file at path, refusing one larger than limit bytes with ErrTooLarge before reading it. A missing file is an error matching fs.ErrNotExist.
Types ¶
type Paths ¶
type Paths struct {
Root string // the per-user data directory
DB string // the SQLite database file
Prompts string // the copy of the prompt library kept beside the database
LaunchDefaults string // the copy of the launch defaults kept beside the database
Backups string // the copies of the user's setup an import saves before it changes anything
Launch string // generated launch scripts and prompt files
Logs string // log files
}
Paths are the application's data locations, all under one root directory.