Skip to content

Commit 488edf4

Browse files
committed
prefix the filename with the lastDir from the path
1 parent 3e04000 commit 488edf4

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
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.%s.yaml", node.Filename(), 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.%s.checksum", node.Filename(), 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Node interface {
2020
Remote() bool
2121
ResolveEntrypoint(entrypoint string) (string, error)
2222
ResolveDir(dir string) (string, error)
23-
Filename() string
23+
FilenameAndLastDir() (string, string)
2424
}
2525

2626
func NewRootNode(

taskfile/node_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ func (node *FileNode) ResolveDir(dir string) (string, error) {
113113
return filepathext.SmartJoin(entrypointDir, path), nil
114114
}
115115

116-
func (node *FileNode) Filename() string {
117-
return filepath.Base(node.Entrypoint)
116+
func (node *FileNode) FilenameAndLastDir() (string, string) {
117+
return "", filepath.Base(node.Entrypoint)
118118
}

taskfile/node_http.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func (node *HTTPNode) ResolveDir(dir string) (string, error) {
111111
return filepathext.SmartJoin(entrypointDir, path), nil
112112
}
113113

114-
func (node *HTTPNode) Filename() string {
115-
return filepath.Base(node.URL.Path)
114+
func (node *HTTPNode) FilenameAndLastDir() (string, string) {
115+
dir, filename := filepath.Split(node.URL.Path)
116+
return filepath.Base(dir), filename
116117
}

taskfile/node_stdin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ func (node *StdinNode) ResolveDir(dir string) (string, error) {
7373
return filepathext.SmartJoin(node.Dir(), path), nil
7474
}
7575

76-
func (node *StdinNode) Filename() string {
77-
return "__stdin__"
76+
func (node *StdinNode) FilenameAndLastDir() (string, string) {
77+
return "", "__stdin__"
7878
}

0 commit comments

Comments
 (0)