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 <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2023-06-04 20:02:40 +10:00
parent 63dc31a80a
commit 07c8c8e17a
No known key found for this signature in database
GPG Key ID: 2897FAD2B7E9446F
1 changed files with 5 additions and 1 deletions

View File

@ -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