Skip to content

Commit 75149d8

Browse files
Merge pull request #7 from inteon/change_temp_dir
Also use cache dir as temporary directory, solving cross-disk copy errors
2 parents 1da07ea + e2d88b8 commit 75149d8

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

pkg/cache/clone.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func calculateCacheKey(src mod.KloneSource) string {
15-
return fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%s", src.RepoURL, src.RepoHash, src.RepoPath))))[:30]
15+
return fmt.Sprintf("cache-%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%s", src.RepoURL, src.RepoHash, src.RepoPath))))[:30]
1616
}
1717

1818
func getCacheDir() (string, error) {
@@ -28,14 +28,6 @@ func getCacheDir() (string, error) {
2828
return filepath.Abs(filepath.Clean(filepath.Join(home, ".cache", "klone")))
2929
}
3030

31-
func getTempDir() (string, error) {
32-
if tempDir := os.Getenv("KLONE_TEMP_DIR"); tempDir != "" {
33-
return filepath.Abs(filepath.Clean(tempDir))
34-
}
35-
36-
return os.TempDir(), nil
37-
}
38-
3931
func CloneWithCache(
4032
destPath string,
4133
src mod.KloneSource,
@@ -46,17 +38,16 @@ func CloneWithCache(
4638
return err
4739
}
4840

41+
if err := os.MkdirAll(cacheDir, 0755); err != nil {
42+
return err
43+
}
44+
4945
cachePath := filepath.Join(cacheDir, calculateCacheKey(src))
5046

5147
if _, err := os.Stat(cachePath); err != nil && !os.IsNotExist(err) {
5248
return err
5349
} else if err != nil {
54-
tmpParentDir, err := getTempDir()
55-
if err != nil {
56-
return err
57-
}
58-
59-
tempDir, err := os.MkdirTemp(tmpParentDir, "klone-*")
50+
tempDir, err := os.MkdirTemp(cacheDir, "temp-*")
6051
if err != nil {
6152
return err
6253
}

0 commit comments

Comments
 (0)