Merge pull request #80 from nwg-piotr/lockfile

Move lock file to XDG_DATA_HOME/nwg-drawer/
This commit is contained in:
Piotr Miller
2022-12-11 23:21:32 +01:00
committed by GitHub
2 changed files with 16 additions and 13 deletions

View File

@@ -21,7 +21,7 @@ import (
"github.com/gotk3/gotk3/gtk"
)
const version = "0.3.5"
const version = "0.3.6"
var (
appDirs []string
@@ -189,7 +189,7 @@ func main() {
// Otherwise the command may behave in two ways:
// 1. kill the running non-residennt instance and exit;
// 2. die if a resident instance found.
lockFilePath := path.Join(tempDir(), "nwg-drawer.lock")
lockFilePath := path.Join(dataDir(), "nwg-drawer.lock")
lockFile, err := singleinstance.CreateLockFile(lockFilePath)
if err != nil {
pid, err := readTextFile(lockFilePath)

View File

@@ -131,17 +131,6 @@ func cacheDir() string {
return ""
}
func tempDir() string {
if os.Getenv("TMPDIR") != "" {
return os.Getenv("TMPDIR")
} else if os.Getenv("TEMP") != "" {
return os.Getenv("TEMP")
} else if os.Getenv("TMP") != "" {
return os.Getenv("TMP")
}
return "/tmp"
}
func readTextFile(path string) (string, error) {
bytes, err := os.ReadFile(path)
if err != nil {
@@ -177,6 +166,20 @@ func configDir() string {
return dir
}
func dataDir() string {
var dir string
if os.Getenv("XDG_DATA_HOME") != "" {
dir = path.Join(os.Getenv("XDG_DATA_HOME"), "nwg-drawer")
} else if os.Getenv("HOME") != "" {
dir = path.Join(os.Getenv("HOME"), ".local/share/nwg-drawer")
}
log.Infof("Data dir: %s", dir)
createDir(dir)
return dir
}
func createDir(dir string) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, os.ModePerm)