-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v3] Added AppDataDirectory path (#3823)
* Added appData * Updated changelog * Updated doc and added error handling and fallbacks * Updated doc * Expose XDG methods * Refactor Path method. Add Paths method * Fix changelog --------- Co-authored-by: Anshuman <anshuman@instasafe.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
- Loading branch information
1 parent
0b1ef79
commit 331097f
Showing
6 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package application | ||
|
||
import "github.com/adrg/xdg" | ||
|
||
type Path int | ||
|
||
const ( | ||
// PathHome is the user's home directory. | ||
PathHome Path = iota | ||
|
||
// PathDataHome defines the base directory relative to which user-specific | ||
// data files should be stored. This directory is defined by the | ||
// $XDG_DATA_HOME environment variable. If the variable is not set, | ||
// a default equal to $HOME/.local/share should be used. | ||
PathDataHome | ||
|
||
// PathConfigHome defines the base directory relative to which user-specific | ||
// configuration files should be written. This directory is defined by | ||
// the $XDG_CONFIG_HOME environment variable. If the variable is | ||
// not set, a default equal to $HOME/.config should be used. | ||
PathConfigHome | ||
|
||
// PathStateHome defines the base directory relative to which user-specific | ||
// state files should be stored. This directory is defined by the | ||
// $XDG_STATE_HOME environment variable. If the variable is not set, | ||
// a default equal to ~/.local/state should be used. | ||
PathStateHome | ||
|
||
// PathCacheHome defines the base directory relative to which user-specific | ||
// non-essential (cached) data should be written. This directory is | ||
// defined by the $XDG_CACHE_HOME environment variable. If the variable | ||
// is not set, a default equal to $HOME/.cache should be used. | ||
PathCacheHome | ||
|
||
// PathRuntimeDir defines the base directory relative to which user-specific | ||
// non-essential runtime files and other file objects (such as sockets, | ||
// named pipes, etc.) should be stored. This directory is defined by the | ||
// $XDG_RUNTIME_DIR environment variable. If the variable is not set, | ||
// applications should fall back to a replacement directory with similar | ||
// capabilities. Applications should use this directory for communication | ||
// and synchronization purposes and should not place larger files in it, | ||
// since it might reside in runtime memory and cannot necessarily be | ||
// swapped out to disk. | ||
PathRuntimeDir | ||
|
||
// PathDesktop defines the location of the user's desktop directory. | ||
PathDesktop | ||
|
||
// PathDownload defines a suitable location for user downloaded files. | ||
PathDownload | ||
|
||
// PathDocuments defines a suitable location for user document files. | ||
PathDocuments | ||
|
||
// PathMusic defines a suitable location for user audio files. | ||
PathMusic | ||
|
||
// PathPictures defines a suitable location for user image files. | ||
PathPictures | ||
|
||
// PathVideos defines a suitable location for user video files. | ||
PathVideos | ||
|
||
// PathTemplates defines a suitable location for user template files. | ||
PathTemplates | ||
|
||
// PathPublicShare defines a suitable location for user shared files. | ||
PathPublicShare | ||
) | ||
|
||
var paths = map[Path]string{ | ||
PathHome: xdg.Home, | ||
PathDataHome: xdg.DataHome, | ||
PathConfigHome: xdg.ConfigHome, | ||
PathStateHome: xdg.StateHome, | ||
PathCacheHome: xdg.CacheHome, | ||
PathRuntimeDir: xdg.RuntimeDir, | ||
PathDesktop: xdg.UserDirs.Desktop, | ||
PathDownload: xdg.UserDirs.Download, | ||
PathDocuments: xdg.UserDirs.Documents, | ||
PathMusic: xdg.UserDirs.Music, | ||
PathPictures: xdg.UserDirs.Pictures, | ||
PathVideos: xdg.UserDirs.Videos, | ||
PathTemplates: xdg.UserDirs.Templates, | ||
PathPublicShare: xdg.UserDirs.PublicShare, | ||
} | ||
|
||
type Paths int | ||
|
||
const ( | ||
// PathsDataDirs defines the preference-ordered set of base directories to | ||
// search for data files in addition to the DataHome base directory. | ||
// This set of directories is defined by the $XDG_DATA_DIRS environment | ||
// variable. If the variable is not set, the default directories | ||
// to be used are /usr/local/share and /usr/share, in that order. The | ||
// DataHome directory is considered more important than any of the | ||
// directories defined by DataDirs. Therefore, user data files should be | ||
// written relative to the DataHome directory, if possible. | ||
PathsDataDirs = iota | ||
|
||
// PathsConfigDirs defines the preference-ordered set of base directories | ||
// search for configuration files in addition to the ConfigHome base | ||
// directory. This set of directories is defined by the $XDG_CONFIG_DIRS | ||
// environment variable. If the variable is not set, a default equal | ||
// to /etc/xdg should be used. The ConfigHome directory is considered | ||
// more important than any of the directories defined by ConfigDirs. | ||
// Therefore, user config files should be written relative to the | ||
// ConfigHome directory, if possible. | ||
PathsConfigDirs | ||
|
||
// PathsFontDirs defines the common locations where font files are stored. | ||
PathsFontDirs | ||
|
||
// PathsApplicationDirs defines the common locations of applications. | ||
PathsApplicationDirs | ||
) | ||
|
||
var pathdirs = map[Paths][]string{ | ||
PathsDataDirs: xdg.DataDirs, | ||
PathsConfigDirs: xdg.ConfigDirs, | ||
PathsFontDirs: xdg.FontDirs, | ||
PathsApplicationDirs: xdg.ApplicationDirs, | ||
} |