Skip to content

Commit 6012da7

Browse files
authored
feat(remote): prefix checksums/cached files with the filename (#1636)
* feat(remote): add the task filename in the checksum / cache filename * prefix the filename with the lastDir from the path
1 parent 46c5eaf commit 6012da7

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

taskfile/cache.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,19 @@ func (c *Cache) key(node Node) string {
5050
}
5151

5252
func (c *Cache) cacheFilePath(node Node) string {
53-
return filepath.Join(c.dir, fmt.Sprintf("%s.yaml", c.key(node)))
53+
return c.filePath(node, "yaml")
5454
}
5555

5656
func (c *Cache) checksumFilePath(node Node) string {
57-
return filepath.Join(c.dir, fmt.Sprintf("%s.checksum", c.key(node)))
57+
return c.filePath(node, "checksum")
58+
}
59+
60+
func (c *Cache) filePath(node Node, suffix string) string {
61+
lastDir, filename := node.FilenameAndLastDir()
62+
prefix := filename
63+
// Means it's not "", nor "." nor "/", so it's a valid directory
64+
if len(lastDir) > 1 {
65+
prefix = fmt.Sprintf("%s-%s", lastDir, filename)
66+
}
67+
return filepath.Join(c.dir, fmt.Sprintf("%s.%s.%s", prefix, c.key(node), suffix))
5868
}

taskfile/node.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Node interface {
2020
Remote() bool
2121
ResolveEntrypoint(entrypoint string) (string, error)
2222
ResolveDir(dir string) (string, error)
23+
FilenameAndLastDir() (string, string)
2324
}
2425

2526
func NewRootNode(

taskfile/node_file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ func (node *FileNode) ResolveDir(dir string) (string, error) {
112112
entrypointDir := filepath.Dir(node.Entrypoint)
113113
return filepathext.SmartJoin(entrypointDir, path), nil
114114
}
115+
116+
func (node *FileNode) FilenameAndLastDir() (string, string) {
117+
return "", filepath.Base(node.Entrypoint)
118+
}

taskfile/node_http.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ func (node *HTTPNode) ResolveDir(dir string) (string, error) {
110110
entrypointDir := filepath.Dir(node.Dir())
111111
return filepathext.SmartJoin(entrypointDir, path), nil
112112
}
113+
114+
func (node *HTTPNode) FilenameAndLastDir() (string, string) {
115+
dir, filename := filepath.Split(node.URL.Path)
116+
return filepath.Base(dir), filename
117+
}

taskfile/node_stdin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ func (node *StdinNode) ResolveDir(dir string) (string, error) {
7272

7373
return filepathext.SmartJoin(node.Dir(), path), nil
7474
}
75+
76+
func (node *StdinNode) FilenameAndLastDir() (string, string) {
77+
return "", "__stdin__"
78+
}

0 commit comments

Comments
 (0)