From 07c8c8e17ae72742b2034a39c2281518ef27a224 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Sun, 4 Jun 2023 20:02:40 +1000 Subject: [PATCH] parse: clean path after checking if entry is a FullType The spec[1] doesn't mention anything about cleaning paths, but it does explicitly refer to the path containing a "/". Cleaning the path before checking if the entry is a FullType would result in the simplest way of forcing directories to be FullTypes (appending a "/" to the pathname of any directory) not working with go-mtree. [1]: https://man.netbsd.org/mtree.5 Signed-off-by: Aleksa Sarai --- parse.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/parse.go b/parse.go index 9094508..e385eaf 100644 --- a/parse.go +++ b/parse.go @@ -75,7 +75,7 @@ func ParseSpec(r io.Reader) (*DirectoryHierarchy, error) { // parse the options f := strings.Fields(str) - e.Name = filepath.Clean(f[0]) + e.Name = f[0] e.Keywords = StringToKeyVals(f[1:]) // TODO: gather keywords if using tar stream var isDir bool @@ -97,6 +97,10 @@ func ParseSpec(r io.Reader) (*DirectoryHierarchy, error) { creator.curEnt = &e } e.Set = creator.curSet + // we need to clean the filepath at the end because '/'s can be + // stripped, which would cause FullTypes to be treated as + // RelativeTypes above + e.Name = filepath.Clean(e.Name) default: // TODO(vbatts) log a warning? continue