From 9ce352249ce4714b5bde81b791db3848dc512b06 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 21 Apr 2018 12:50:24 -0700 Subject: [PATCH] internal/osutil: move the config dir to perkeep Updates #981 Change-Id: I71ceea6395d31851e8502a2f397acb22056fe1b0 --- internal/osutil/paths.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/osutil/paths.go b/internal/osutil/paths.go index b94a9ac86..86c25e0ce 100644 --- a/internal/osutil/paths.go +++ b/internal/osutil/paths.go @@ -18,6 +18,7 @@ package osutil import ( "flag" + "fmt" "log" "os" "path/filepath" @@ -127,6 +128,25 @@ func CamliConfigDir() string { } func camliConfigDir() string { + if fi, err := os.Lstat(oldCamliConfigDir()); err == nil && fi.IsDir() { + fmt.Fprintf(os.Stderr, "Error: old configuration directory detected. Not running until it's moved.\nRename %s to %s\n", + oldCamliConfigDir(), perkeepConfigDir()) + os.Exit(1) + } + return perkeepConfigDir() +} + +func perkeepConfigDir() string { + if runtime.GOOS == "windows" { + return filepath.Join(os.Getenv("APPDATA"), "Perkeep") + } + if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" { + return filepath.Join(xdg, "perkeep") + } + return filepath.Join(HomeDir(), ".config", "perkeep") +} + +func oldCamliConfigDir() string { if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("APPDATA"), "Camlistore") }