@@ -12,7 +12,7 @@ import (
12
12
)
13
13
14
14
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 ]
16
16
}
17
17
18
18
func getCacheDir () (string , error ) {
@@ -28,14 +28,6 @@ func getCacheDir() (string, error) {
28
28
return filepath .Abs (filepath .Clean (filepath .Join (home , ".cache" , "klone" )))
29
29
}
30
30
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
-
39
31
func CloneWithCache (
40
32
destPath string ,
41
33
src mod.KloneSource ,
@@ -46,17 +38,16 @@ func CloneWithCache(
46
38
return err
47
39
}
48
40
41
+ if err := os .MkdirAll (cacheDir , 0755 ); err != nil {
42
+ return err
43
+ }
44
+
49
45
cachePath := filepath .Join (cacheDir , calculateCacheKey (src ))
50
46
51
47
if _ , err := os .Stat (cachePath ); err != nil && ! os .IsNotExist (err ) {
52
48
return err
53
49
} 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-*" )
60
51
if err != nil {
61
52
return err
62
53
}
0 commit comments