From 96998e167a915b99c9d91f46e59b9b52edd1ace2 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Fri, 3 May 2024 09:35:33 +0200 Subject: [PATCH] also use cache dir as temporary directory, solving cross-disk copy errors Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- pkg/cache/clone.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pkg/cache/clone.go b/pkg/cache/clone.go index 88bf54c..979a4f4 100644 --- a/pkg/cache/clone.go +++ b/pkg/cache/clone.go @@ -12,7 +12,7 @@ import ( ) func calculateCacheKey(src mod.KloneSource) string { - return fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%s", src.RepoURL, src.RepoHash, src.RepoPath))))[:30] + return fmt.Sprintf("cache-%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%s", src.RepoURL, src.RepoHash, src.RepoPath))))[:30] } func getCacheDir() (string, error) { @@ -28,14 +28,6 @@ func getCacheDir() (string, error) { return filepath.Abs(filepath.Clean(filepath.Join(home, ".cache", "klone"))) } -func getTempDir() (string, error) { - if tempDir := os.Getenv("KLONE_TEMP_DIR"); tempDir != "" { - return filepath.Abs(filepath.Clean(tempDir)) - } - - return os.TempDir(), nil -} - func CloneWithCache( destPath string, src mod.KloneSource, @@ -51,12 +43,7 @@ func CloneWithCache( if _, err := os.Stat(cachePath); err != nil && !os.IsNotExist(err) { return err } else if err != nil { - tmpParentDir, err := getTempDir() - if err != nil { - return err - } - - tempDir, err := os.MkdirTemp(tmpParentDir, "klone-*") + tempDir, err := os.MkdirTemp(cacheDir, "temp-*") if err != nil { return err }