Skip to content

Commit

Permalink
Merge pull request #80 from nwg-piotr/lockfile
Browse files Browse the repository at this point in the history
Move lock file to XDG_DATA_HOME/nwg-drawer/
  • Loading branch information
nwg-piotr authored Dec 11, 2022
2 parents d22609f + ab5e2ea commit c4629e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/gotk3/gotk3/gtk"
)

const version = "0.3.5"
const version = "0.3.6"

var (
appDirs []string
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 14 additions & 11 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c4629e0

Please sign in to comment.