From 6823b5303a062912828496e0fc524c65bb094eb4 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Thu, 9 May 2024 13:02:45 +0200 Subject: [PATCH] prefix the filename with the lastDir from the path --- taskfile/cache.go | 14 ++++++++++++-- taskfile/node.go | 2 +- taskfile/node_file.go | 4 ++-- taskfile/node_http.go | 5 +++-- taskfile/node_stdin.go | 4 ++-- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/taskfile/cache.go b/taskfile/cache.go index 8ca5e8448d..37c69ebef1 100644 --- a/taskfile/cache.go +++ b/taskfile/cache.go @@ -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() + var 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)) } diff --git a/taskfile/node.go b/taskfile/node.go index 55e6b2c143..332561923c 100644 --- a/taskfile/node.go +++ b/taskfile/node.go @@ -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( diff --git a/taskfile/node_file.go b/taskfile/node_file.go index adb285fd60..3e5ec9d69e 100644 --- a/taskfile/node_file.go +++ b/taskfile/node_file.go @@ -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) } diff --git a/taskfile/node_http.go b/taskfile/node_http.go index 1dd95c787c..e21c2c7130 100644 --- a/taskfile/node_http.go +++ b/taskfile/node_http.go @@ -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 } diff --git a/taskfile/node_stdin.go b/taskfile/node_stdin.go index 938886847f..3855415dae 100644 --- a/taskfile/node_stdin.go +++ b/taskfile/node_stdin.go @@ -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__" }