From 60cd0d75cd083364aa52bbfa943097bcaa1471ff Mon Sep 17 00:00:00 2001 From: Simon Let Date: Thu, 19 Jan 2023 00:33:06 +0100 Subject: [PATCH] minor cleanup --- cmd/daemon/main.go | 2 +- cmd/install-utils/migrate.go | 6 ++---- internal/datadir/datadir.go | 39 ++---------------------------------- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go index cbdc0df..cc0a108 100644 --- a/cmd/daemon/main.go +++ b/cmd/daemon/main.go @@ -48,7 +48,7 @@ func main() { } // TODO: These paths should be probably defined in a package pidFile := filepath.Join(dataDir, "daemon.pid") - reshHistoryPath := filepath.Join(dataDir, "history.reshjson") + reshHistoryPath := filepath.Join(dataDir, datadir.HistoryFileName) bashHistoryPath := filepath.Join(homeDir, ".bash_history") zshHistoryPath := filepath.Join(homeDir, ".zsh_history") deviceID, err := device.GetID(dataDir) diff --git a/cmd/install-utils/migrate.go b/cmd/install-utils/migrate.go index 17c5eb5..f504ca1 100644 --- a/cmd/install-utils/migrate.go +++ b/cmd/install-utils/migrate.go @@ -102,8 +102,7 @@ func migrateHistoryLocation(out *output.Output) error { if err != nil { return fmt.Errorf("failed to get data directory: %w", err) } - // TODO: de-hardcode this - historyPath := path.Join(dataDir, "history.reshjson") + historyPath := path.Join(dataDir, datadir.HistoryFileName) exists, err := futil.FileExists(historyPath) if err != nil { @@ -149,8 +148,7 @@ func migrateHistoryFormat(out *output.Output) error { if err != nil { return fmt.Errorf("could not get user data directory: %w", err) } - // TODO: de-hardcode this - historyPath := path.Join(dataDir, "history.reshjson") + historyPath := path.Join(dataDir, datadir.HistoryFileName) exists, err := futil.FileExists(historyPath) if err != nil { diff --git a/internal/datadir/datadir.go b/internal/datadir/datadir.go index 59011dd..fea36f8 100644 --- a/internal/datadir/datadir.go +++ b/internal/datadir/datadir.go @@ -6,43 +6,8 @@ import ( "path" ) -// You should not need this caching -// It messes with proper dependency injection -// Find another way - -// type dirCache struct { -// dir string -// err error -// -// cached bool -// } -// -// var cache dirCache -// -// func getPathNoCache() (string, error) { -// reshDir := "resh" -// xdgDir, found := os.LookupEnv("XDG_DATA_HOME") -// if found { -// return path.Join(xdgDir, reshDir), nil -// } -// homeDir, err := os.UserHomeDir() -// if err != nil { -// return "", fmt.Errorf("error while getting home dir: %w", err) -// } -// return path.Join(homeDir, ".local/share/", reshDir), nil -// } -// -// func GetPath() (string, error) { -// if !cache.cached { -// dir, err := getPathNoCache() -// cache = dirCache{ -// dir: dir, -// err: err, -// cached: true, -// } -// } -// return cache.dir, cache.err -// } +// Maybe there is a better place for this constant +const HistoryFileName = "history.reshjson" func GetPath() (string, error) { reshDir := "resh"