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 <[email protected]>
  • Loading branch information
inteon committed May 3, 2024
1 parent adc9c9b commit c1f8ebd
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions pkg/cache/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"time"

"github.com/cert-manager/klone/pkg/mod"
cp "github.com/otiai10/copy"
)

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 +27,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 +42,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 c1f8ebd

Please sign in to comment.