Skip to content

Commit

Permalink
build tags; CutPrefix not in go1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlehane committed May 28, 2023
1 parent 6ca20bb commit 09dbd54
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/config/archivematica.go
@@ -1,4 +1,4 @@
// +build archivematica
//go:build archivematica

package config

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/brew.go
@@ -1,4 +1,4 @@
// +build brew
//go:build brew

package config

Expand Down
7 changes: 2 additions & 5 deletions pkg/config/default.go
@@ -1,5 +1,4 @@
//go:build !brew && !archivematica && !js
// +build !brew,!archivematica,!js

// Copyright 2014 Richard Lehane. All rights reserved.
//
Expand Down Expand Up @@ -51,14 +50,12 @@ func init() {
func xdgPath(home string, defaultPath string) string {
dataHome, found := os.LookupEnv("XDG_DATA_HOME")
if found && dataHome != "" {
if dataDir, found := strings.CutPrefix(dataHome, "~"); found {
dataHome = filepath.Join(home, dataDir)
if strings.HasPrefix(dataHome, "~") {
dataHome = filepath.Join(home, strings.TrimPrefix(dataHome, "~"))
}

// environment variable might contain variables like $HOME itself, let's expand
dataHome = os.ExpandEnv(dataHome)
}

// XDG Base Directory Specification demands relative paths to be ignored, fall back to default in that case
if filepath.IsAbs(dataHome) {
return dataHome
Expand Down
4 changes: 1 addition & 3 deletions pkg/config/default_darwin.go
@@ -1,5 +1,4 @@
//go:build darwin && !brew && !archivematica && !js
// +build darwin,!brew,!archivematica,!js
//go:build !brew && !archivematica && !js

// Copyright 2014 Richard Lehane. All rights reserved.
//
Expand All @@ -21,7 +20,6 @@ import (
"path/filepath"
)


func userDataDir(home string) string {
return xdgPath(home, filepath.Join("Library", "Application Support"))
}
4 changes: 1 addition & 3 deletions pkg/config/default_plan9.go
@@ -1,5 +1,4 @@
//go:build plan9 && !brew && !archivematica && !js
// +build plan9,!brew,!archivematica,!js
//go:build !brew && !archivematica && !js

// Copyright 2014 Richard Lehane. All rights reserved.
//
Expand All @@ -17,7 +16,6 @@

package config


func userDataDir(home string) string {
return xdgPath(home, "lib")
}
7 changes: 1 addition & 6 deletions pkg/config/default_unix.go
@@ -1,8 +1,4 @@
//go:build (aix || darwin || dragonfly || freebsd || nacl || linux || netbsd || openbsd || solaris) && !brew && !archivematica && !js
// +build aix darwin dragonfly freebsd nacl linux netbsd openbsd solaris
// +build !brew
// +build !archivematica
// +build !js
//go:build (aix || dragonfly || freebsd || nacl || linux || netbsd || openbsd || solaris) && !brew && !archivematica && !js

// Copyright 2014 Richard Lehane. All rights reserved.
//
Expand All @@ -20,7 +16,6 @@

package config


func userDataDir(home string) string {
return xdgPath(home, ".local/share")
}
10 changes: 3 additions & 7 deletions pkg/config/default_windows.go
@@ -1,5 +1,4 @@
//go:build windows && !brew && !archivematica && !js
// +build windows,!brew,!archivematica,!js
//go:build !brew && !archivematica && !js

// Copyright 2014 Richard Lehane. All rights reserved.
//
Expand All @@ -24,13 +23,11 @@ import (
"golang.org/x/sys/windows"
)


func userDataDir(home string) string {
path, _ := windows.KnownFolderPath(*windows.FOLDERID_LocalAppData, windows.KF_FLAG_DEFAULT|KF_FLAG_DONT_VERIFY)
path, _ := windows.KnownFolderPath(windows.FOLDERID_LocalAppData, windows.KF_FLAG_DEFAULT|windows.KF_FLAG_DONT_VERIFY)
if path == "" {
path, _ = windows.KnownFolderPath(*windows.FOLDERID_LocalAppData, windows.KF_FLAG_DEFAULT_PATH|KF_FLAG_DONT_VERIFY)
path, _ = windows.KnownFolderPath(windows.FOLDERID_LocalAppData, windows.KF_FLAG_DEFAULT_PATH|windows.KF_FLAG_DONT_VERIFY)
}

if path == "" {
dataDir, found := os.LookupEnv("LOCALAPPDATA")
if found && dataDir != "" {
Expand All @@ -39,6 +36,5 @@ func userDataDir(home string) string {
path = filepath.Join("AppData", "Local")
}
}

return xdgPath(home, path)
}

0 comments on commit 09dbd54

Please sign in to comment.