Skip to content

Commit

Permalink
also use cache dir as temporary directory, solving cross-disk copy er…
Browse files Browse the repository at this point in the history
…rors

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed May 3, 2024
1 parent adc9c9b commit 96998e1
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions pkg/cache/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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
}
Expand Down

0 comments on commit 96998e1

Please sign in to comment.