mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-12-18 03:56:30 +00:00
Merge pull request #188 from cyphar/parse-fulltype-handling
parse: improve FullType handling
This commit is contained in:
commit
7c8a752a64
1 changed files with 20 additions and 13 deletions
33
parse.go
33
parse.go
|
@ -72,28 +72,35 @@ func ParseSpec(r io.Reader) (*DirectoryHierarchy, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the options
|
// parse the options
|
||||||
f := strings.Fields(str)
|
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
|
||||||
|
for _, kv := range e.Keywords {
|
||||||
|
if kv.Keyword() == "type" {
|
||||||
|
isDir = kv.Value() == "dir"
|
||||||
|
}
|
||||||
|
}
|
||||||
if strings.Contains(e.Name, "/") {
|
if strings.Contains(e.Name, "/") {
|
||||||
e.Type = FullType
|
e.Type = FullType
|
||||||
} else {
|
} else {
|
||||||
e.Type = RelativeType
|
e.Type = RelativeType
|
||||||
}
|
e.Parent = creator.curDir
|
||||||
e.Keywords = StringToKeyVals(f[1:])
|
if isDir {
|
||||||
// TODO: gather keywords if using tar stream
|
creator.curDir = &e
|
||||||
e.Parent = creator.curDir
|
|
||||||
for i := range e.Keywords {
|
|
||||||
kv := KeyVal(e.Keywords[i])
|
|
||||||
if kv.Keyword() == "type" {
|
|
||||||
if kv.Value() == "dir" {
|
|
||||||
creator.curDir = &e
|
|
||||||
} else {
|
|
||||||
creator.curEnt = &e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !isDir {
|
||||||
|
creator.curEnt = &e
|
||||||
|
}
|
||||||
e.Set = creator.curSet
|
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:
|
default:
|
||||||
// TODO(vbatts) log a warning?
|
// TODO(vbatts) log a warning?
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue