Skip to content

Commit

Permalink
Replace xdgPath and xdgPaths calls with pathutil equivalents
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Jul 7, 2024
1 parent 9d18656 commit 28fbf4c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 60 deletions.
31 changes: 16 additions & 15 deletions paths_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xdg
import (
"path/filepath"

"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)

Expand All @@ -16,17 +17,17 @@ func initBaseDirs(home string) {
rootAppSupport := "/Library/Application Support"

// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, homeAppSupport)
baseDirs.data = xdgPaths(envDataDirs, rootAppSupport)
baseDirs.configHome = xdgPath(envConfigHome, homeAppSupport)
baseDirs.config = xdgPaths(envConfigDirs,
baseDirs.dataHome = pathutil.EnvPath(envDataHome, homeAppSupport)
baseDirs.data = pathutil.EnvPathList(envDataDirs, rootAppSupport)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, homeAppSupport)
baseDirs.config = pathutil.EnvPathList(envConfigDirs,
filepath.Join(home, "Library", "Preferences"),
rootAppSupport,
"/Library/Preferences",
)
baseDirs.stateHome = xdgPath(envStateHome, homeAppSupport)
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(home, "Library", "Caches"))
baseDirs.runtime = xdgPath(envRuntimeDir, homeAppSupport)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, homeAppSupport)
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(home, "Library", "Caches"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, homeAppSupport)

// Initialize non-standard directories.
baseDirs.applications = []string{
Expand All @@ -42,12 +43,12 @@ func initBaseDirs(home string) {
}

func initUserDirs(home string) {
UserDirs.Desktop = xdgPath(userdirs.EnvDesktopDir, filepath.Join(home, "Desktop"))
UserDirs.Download = xdgPath(userdirs.EnvDownloadDir, filepath.Join(home, "Downloads"))
UserDirs.Documents = xdgPath(userdirs.EnvDocumentsDir, filepath.Join(home, "Documents"))
UserDirs.Music = xdgPath(userdirs.EnvMusicDir, filepath.Join(home, "Music"))
UserDirs.Pictures = xdgPath(userdirs.EnvPicturesDir, filepath.Join(home, "Pictures"))
UserDirs.Videos = xdgPath(userdirs.EnvVideosDir, filepath.Join(home, "Movies"))
UserDirs.Templates = xdgPath(userdirs.EnvTemplatesDir, filepath.Join(home, "Templates"))
UserDirs.PublicShare = xdgPath(userdirs.EnvPublicShareDir, filepath.Join(home, "Public"))
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, filepath.Join(home, "Desktop"))
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, filepath.Join(home, "Downloads"))
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, filepath.Join(home, "Documents"))
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, filepath.Join(home, "Music"))
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, filepath.Join(home, "Pictures"))
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, filepath.Join(home, "Movies"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, filepath.Join(home, "Templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, filepath.Join(home, "Public"))
}
31 changes: 16 additions & 15 deletions paths_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xdg
import (
"path/filepath"

"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)

Expand All @@ -16,13 +17,13 @@ func initBaseDirs(home string) {
rootLibDir := "/lib"

// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, homeLibDir)
baseDirs.data = xdgPaths(envDataDirs, rootLibDir)
baseDirs.configHome = xdgPath(envConfigHome, homeLibDir)
baseDirs.config = xdgPaths(envConfigDirs, rootLibDir)
baseDirs.stateHome = xdgPath(envStateHome, filepath.Join(homeLibDir, "state"))
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(homeLibDir, "cache"))
baseDirs.runtime = xdgPath(envRuntimeDir, "/tmp")
baseDirs.dataHome = pathutil.EnvPath(envDataHome, homeLibDir)
baseDirs.data = pathutil.EnvPathList(envDataDirs, rootLibDir)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, homeLibDir)
baseDirs.config = pathutil.EnvPathList(envConfigDirs, rootLibDir)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, filepath.Join(homeLibDir, "state"))
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(homeLibDir, "cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, "/tmp")

// Initialize non-standard directories.
baseDirs.applications = []string{
Expand All @@ -37,12 +38,12 @@ func initBaseDirs(home string) {
}

func initUserDirs(home string) {
UserDirs.Desktop = xdgPath(userdirs.EnvDesktopDir, filepath.Join(home, "desktop"))
UserDirs.Download = xdgPath(userdirs.EnvDownloadDir, filepath.Join(home, "downloads"))
UserDirs.Documents = xdgPath(userdirs.EnvDocumentsDir, filepath.Join(home, "documents"))
UserDirs.Music = xdgPath(userdirs.EnvMusicDir, filepath.Join(home, "music"))
UserDirs.Pictures = xdgPath(userdirs.EnvPicturesDir, filepath.Join(home, "pictures"))
UserDirs.Videos = xdgPath(userdirs.EnvVideosDir, filepath.Join(home, "videos"))
UserDirs.Templates = xdgPath(userdirs.EnvTemplatesDir, filepath.Join(home, "templates"))
UserDirs.PublicShare = xdgPath(userdirs.EnvPublicShareDir, filepath.Join(home, "public"))
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, filepath.Join(home, "desktop"))
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, filepath.Join(home, "downloads"))
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, filepath.Join(home, "documents"))
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, filepath.Join(home, "music"))
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, filepath.Join(home, "pictures"))
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, filepath.Join(home, "videos"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, filepath.Join(home, "templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, filepath.Join(home, "public"))
}
30 changes: 15 additions & 15 deletions paths_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func initDirs(home string) {

func initBaseDirs(home string) {
// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, filepath.Join(home, ".local", "share"))
baseDirs.data = xdgPaths(envDataDirs, "/usr/local/share", "/usr/share")
baseDirs.configHome = xdgPath(envConfigHome, filepath.Join(home, ".config"))
baseDirs.config = xdgPaths(envConfigDirs, "/etc/xdg")
baseDirs.stateHome = xdgPath(envStateHome, filepath.Join(home, ".local", "state"))
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(home, ".cache"))
baseDirs.runtime = xdgPath(envRuntimeDir, filepath.Join("/run/user", strconv.Itoa(os.Getuid())))
baseDirs.dataHome = pathutil.EnvPath(envDataHome, filepath.Join(home, ".local", "share"))
baseDirs.data = pathutil.EnvPathList(envDataDirs, "/usr/local/share", "/usr/share")
baseDirs.configHome = pathutil.EnvPath(envConfigHome, filepath.Join(home, ".config"))
baseDirs.config = pathutil.EnvPathList(envConfigDirs, "/etc/xdg")
baseDirs.stateHome = pathutil.EnvPath(envStateHome, filepath.Join(home, ".local", "state"))
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(home, ".cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, filepath.Join("/run/user", strconv.Itoa(os.Getuid())))

// Initialize non-standard directories.
appDirs := []string{
Expand Down Expand Up @@ -54,12 +54,12 @@ func initBaseDirs(home string) {
func initUserDirs(home, configHome string) {
userDirsMap := userdirs.ParseConfigFile(filepath.Join(configHome, "user-dirs.dirs"))

UserDirs.Desktop = xdgPath(userdirs.EnvDesktopDir, userDirsMap[userdirs.EnvDesktopDir], filepath.Join(home, "Desktop"))
UserDirs.Download = xdgPath(userdirs.EnvDownloadDir, userDirsMap[userdirs.EnvDownloadDir], filepath.Join(home, "Downloads"))
UserDirs.Documents = xdgPath(userdirs.EnvDocumentsDir, userDirsMap[userdirs.EnvDocumentsDir], filepath.Join(home, "Documents"))
UserDirs.Music = xdgPath(userdirs.EnvMusicDir, userDirsMap[userdirs.EnvMusicDir], filepath.Join(home, "Music"))
UserDirs.Pictures = xdgPath(userdirs.EnvPicturesDir, userDirsMap[userdirs.EnvPicturesDir], filepath.Join(home, "Pictures"))
UserDirs.Videos = xdgPath(userdirs.EnvVideosDir, userDirsMap[userdirs.EnvVideosDir], filepath.Join(home, "Videos"))
UserDirs.Templates = xdgPath(userdirs.EnvTemplatesDir, userDirsMap[userdirs.EnvTemplatesDir], filepath.Join(home, "Templates"))
UserDirs.PublicShare = xdgPath(userdirs.EnvPublicShareDir, userDirsMap[userdirs.EnvPublicShareDir], filepath.Join(home, "Public"))
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, userDirsMap[userdirs.EnvDesktopDir], filepath.Join(home, "Desktop"))
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, userDirsMap[userdirs.EnvDownloadDir], filepath.Join(home, "Downloads"))
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, userDirsMap[userdirs.EnvDocumentsDir], filepath.Join(home, "Documents"))
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, userDirsMap[userdirs.EnvMusicDir], filepath.Join(home, "Music"))
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, userDirsMap[userdirs.EnvPicturesDir], filepath.Join(home, "Pictures"))
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, userDirsMap[userdirs.EnvVideosDir], filepath.Join(home, "Videos"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, userDirsMap[userdirs.EnvTemplatesDir], filepath.Join(home, "Templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, userDirsMap[userdirs.EnvPublicShareDir], filepath.Join(home, "Public"))
}
30 changes: 15 additions & 15 deletions paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ func initDirs(home string) {

func initBaseDirs(home string, kf *knownFolders) {
// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, kf.localAppData)
baseDirs.data = xdgPaths(envDataDirs, kf.roamingAppData, kf.programData)
baseDirs.configHome = xdgPath(envConfigHome, kf.localAppData)
baseDirs.config = xdgPaths(envConfigDirs, kf.programData, kf.roamingAppData)
baseDirs.stateHome = xdgPath(envStateHome, kf.localAppData)
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(kf.localAppData, "cache"))
baseDirs.runtime = xdgPath(envRuntimeDir, kf.localAppData)
baseDirs.dataHome = pathutil.EnvPath(envDataHome, kf.localAppData)
baseDirs.data = pathutil.EnvPathList(envDataDirs, kf.roamingAppData, kf.programData)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, kf.localAppData)
baseDirs.config = pathutil.EnvPathList(envConfigDirs, kf.programData, kf.roamingAppData)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, kf.localAppData)
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(kf.localAppData, "cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, kf.localAppData)

// Initialize non-standard directories.
baseDirs.applications = []string{
Expand All @@ -36,14 +36,14 @@ func initBaseDirs(home string, kf *knownFolders) {
}

func initUserDirs(home string, kf *knownFolders) {
UserDirs.Desktop = xdgPath(userdirs.EnvDesktopDir, kf.desktop)
UserDirs.Download = xdgPath(userdirs.EnvDownloadDir, kf.downloads)
UserDirs.Documents = xdgPath(userdirs.EnvDocumentsDir, kf.documents)
UserDirs.Music = xdgPath(userdirs.EnvMusicDir, kf.music)
UserDirs.Pictures = xdgPath(userdirs.EnvPicturesDir, kf.pictures)
UserDirs.Videos = xdgPath(userdirs.EnvVideosDir, kf.videos)
UserDirs.Templates = xdgPath(userdirs.EnvTemplatesDir, kf.templates)
UserDirs.PublicShare = xdgPath(userdirs.EnvPublicShareDir, kf.public)
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, kf.desktop)
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, kf.downloads)
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, kf.documents)
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, kf.music)
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, kf.pictures)
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, kf.videos)
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, kf.templates)
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, kf.public)
}

type knownFolders struct {
Expand Down

0 comments on commit 28fbf4c

Please sign in to comment.