Skip to content

Commit

Permalink
prefix the filename with the lastDir from the path
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaerten committed May 10, 2024
1 parent 3e04000 commit 488edf4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
14 changes: 12 additions & 2 deletions taskfile/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ func (c *Cache) key(node Node) string {
}

func (c *Cache) cacheFilePath(node Node) string {
return filepath.Join(c.dir, fmt.Sprintf("%s.%s.yaml", node.Filename(), c.key(node)))
return c.filePath(node, "yaml")
}

func (c *Cache) checksumFilePath(node Node) string {
return filepath.Join(c.dir, fmt.Sprintf("%s.%s.checksum", node.Filename(), c.key(node)))
return c.filePath(node, "checksum")
}

func (c *Cache) filePath(node Node, suffix string) string {
lastDir, filename := node.FilenameAndLastDir()
prefix := filename
// Means it's not "", nor "." nor "/", so it's a valid directory
if len(lastDir) > 1 {
prefix = fmt.Sprintf("%s-%s", lastDir, filename)
}
return filepath.Join(c.dir, fmt.Sprintf("%s.%s.%s", prefix, c.key(node), suffix))
}
2 changes: 1 addition & 1 deletion taskfile/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Node interface {
Remote() bool
ResolveEntrypoint(entrypoint string) (string, error)
ResolveDir(dir string) (string, error)
Filename() string
FilenameAndLastDir() (string, string)
}

func NewRootNode(
Expand Down
4 changes: 2 additions & 2 deletions taskfile/node_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ func (node *FileNode) ResolveDir(dir string) (string, error) {
return filepathext.SmartJoin(entrypointDir, path), nil
}

func (node *FileNode) Filename() string {
return filepath.Base(node.Entrypoint)
func (node *FileNode) FilenameAndLastDir() (string, string) {
return "", filepath.Base(node.Entrypoint)
}
5 changes: 3 additions & 2 deletions taskfile/node_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (node *HTTPNode) ResolveDir(dir string) (string, error) {
return filepathext.SmartJoin(entrypointDir, path), nil
}

func (node *HTTPNode) Filename() string {
return filepath.Base(node.URL.Path)
func (node *HTTPNode) FilenameAndLastDir() (string, string) {
dir, filename := filepath.Split(node.URL.Path)
return filepath.Base(dir), filename
}
4 changes: 2 additions & 2 deletions taskfile/node_stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ func (node *StdinNode) ResolveDir(dir string) (string, error) {
return filepathext.SmartJoin(node.Dir(), path), nil
}

func (node *StdinNode) Filename() string {
return "__stdin__"
func (node *StdinNode) FilenameAndLastDir() (string, string) {
return "", "__stdin__"
}

0 comments on commit 488edf4

Please sign in to comment.