From 32c130f172daced2771bc6d25cfa68365c4ac83b Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Fri, 31 Oct 2025 16:05:51 -0300 Subject: [PATCH] refactor: simplify `home.Dir()` * Realistically, this should almost never fail. * If it does, returning `""` probably makes more sense than a temp dir. Empty means Go will assume the working directory. * Getting rid of `sync.Once` is good as it locks and this can be called on every render cycle. (Used to compute `~` on the sidebar, etc). --- internal/home/home.go | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/internal/home/home.go b/internal/home/home.go index 74ab5594bf19377a86e6e96cae298a91b4858cff..4f65290c32620b253a3df02ab2c7bb6208098b98 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -2,29 +2,16 @@ package home import ( - "log/slog" "os" "path/filepath" "strings" - "sync" ) -// Dir returns the users home directory, or if it fails, tries to create a new -// temporary directory and use that instead. -var Dir = sync.OnceValue(func() string { - home, err := os.UserHomeDir() - if err == nil { - slog.Debug("user home directory", "home", home) - return home - } - tmp, err := os.MkdirTemp("crush", "") - if err != nil { - slog.Error("could not find the user home directory") - return "" - } - slog.Warn("could not find the user home directory, using a temporary one", "home", tmp) - return tmp -}) +// Dir returns the user home directory. +func Dir() string { + home, _ := os.UserHomeDir() + return home +} // Short replaces the actual home path from [Dir] with `~`. func Short(p string) string {