mtree: remove use of dhCreator for iterators
Fix a bug in the parser that caused all iterators to have to handle the /set and /unset semantics separately. In addition, provide a helper function to correctly generate the merged set of keywords for a particular entry. Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
30ae0132eb
commit
36372dd3c8
3 changed files with 23 additions and 36 deletions
45
check.go
45
check.go
|
@ -32,7 +32,6 @@ func (f Failure) String() string {
|
||||||
// the available keywords from the list and each entry in the hierarchy.
|
// the available keywords from the list and each entry in the hierarchy.
|
||||||
// If keywords is nil, the check all present in the DirectoryHierarchy
|
// If keywords is nil, the check all present in the DirectoryHierarchy
|
||||||
func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, error) {
|
func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, error) {
|
||||||
creator := dhCreator{DH: dh}
|
|
||||||
curDir, err := os.Getwd()
|
curDir, err := os.Getwd()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer os.Chdir(curDir)
|
defer os.Chdir(curDir)
|
||||||
|
@ -41,16 +40,11 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
|
||||||
if err := os.Chdir(root); err != nil {
|
if err := os.Chdir(root); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sort.Sort(byPos(creator.DH.Entries))
|
sort.Sort(byPos(dh.Entries))
|
||||||
|
|
||||||
var result Result
|
var result Result
|
||||||
for i, e := range creator.DH.Entries {
|
for _, e := range dh.Entries {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case SpecialType:
|
|
||||||
if e.Name == "/set" {
|
|
||||||
creator.curSet = &creator.DH.Entries[i]
|
|
||||||
} else if e.Name == "/unset" {
|
|
||||||
creator.curSet = nil
|
|
||||||
}
|
|
||||||
case RelativeType, FullType:
|
case RelativeType, FullType:
|
||||||
pathname, err := e.Path()
|
pathname, err := e.Path()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,12 +55,8 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var kvs KeyVals
|
kvs := e.AllKeys()
|
||||||
if creator.curSet != nil {
|
|
||||||
kvs = MergeSet(creator.curSet.Keywords, e.Keywords)
|
|
||||||
} else {
|
|
||||||
kvs = NewKeyVals(e.Keywords)
|
|
||||||
}
|
|
||||||
for _, kv := range kvs {
|
for _, kv := range kvs {
|
||||||
kw := kv.Keyword()
|
kw := kv.Keyword()
|
||||||
// 'tar_time' keyword evaluation wins against 'time' keyword evaluation
|
// 'tar_time' keyword evaluation wins against 'time' keyword evaluation
|
||||||
|
@ -133,18 +123,11 @@ func TarCheck(tarDH, dh *DirectoryHierarchy, keywords []string) (*Result, error)
|
||||||
Type: CommentType,
|
Type: CommentType,
|
||||||
}
|
}
|
||||||
curDir := tarRoot
|
curDir := tarRoot
|
||||||
creator := dhCreator{DH: dh}
|
sort.Sort(byPos(dh.Entries))
|
||||||
sort.Sort(byPos(creator.DH.Entries))
|
|
||||||
|
|
||||||
var outOfTree bool
|
var outOfTree bool
|
||||||
for i, e := range creator.DH.Entries {
|
for _, e := range dh.Entries {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case SpecialType:
|
|
||||||
if e.Name == "/set" {
|
|
||||||
creator.curSet = &creator.DH.Entries[i]
|
|
||||||
} else if e.Name == "/unset" {
|
|
||||||
creator.curSet = nil
|
|
||||||
}
|
|
||||||
case RelativeType, FullType:
|
case RelativeType, FullType:
|
||||||
pathname, err := e.Path()
|
pathname, err := e.Path()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -166,20 +149,10 @@ func TarCheck(tarDH, dh *DirectoryHierarchy, keywords []string) (*Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// expected values from file hierarchy spec
|
// expected values from file hierarchy spec
|
||||||
var kvs KeyVals
|
kvs := e.AllKeys()
|
||||||
if creator.curSet != nil {
|
|
||||||
kvs = MergeSet(creator.curSet.Keywords, e.Keywords)
|
|
||||||
} else {
|
|
||||||
kvs = NewKeyVals(e.Keywords)
|
|
||||||
}
|
|
||||||
|
|
||||||
// actual
|
// actual
|
||||||
var tarkvs KeyVals
|
tarkvs := tarEntry.AllKeys()
|
||||||
if tarEntry.Set != nil {
|
|
||||||
tarkvs = MergeSet(tarEntry.Set.Keywords, tarEntry.Keywords)
|
|
||||||
} else {
|
|
||||||
tarkvs = NewKeyVals(tarEntry.Keywords)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range kvs {
|
for _, kv := range kvs {
|
||||||
// TODO: keep track of symlinks
|
// TODO: keep track of symlinks
|
||||||
|
|
13
entry.go
13
entry.go
|
@ -100,6 +100,19 @@ func (e Entry) String() string {
|
||||||
return fmt.Sprintf(" %s %s", e.Name, strings.Join(e.Keywords, " "))
|
return fmt.Sprintf(" %s %s", e.Name, strings.Join(e.Keywords, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllKeys returns the full set of KeyVals for the given entry, based on the
|
||||||
|
// /set keys as well as the entry-local keys. Entry-local keys always take
|
||||||
|
// precedence.
|
||||||
|
func (e Entry) AllKeys() KeyVals {
|
||||||
|
var kv KeyVals
|
||||||
|
if e.Set != nil {
|
||||||
|
kv = MergeSet(e.Set.Keywords, e.Keywords)
|
||||||
|
} else {
|
||||||
|
kv = NewKeyVals(e.Keywords)
|
||||||
|
}
|
||||||
|
return kv
|
||||||
|
}
|
||||||
|
|
||||||
// EntryType are the formats of lines in an mtree spec file
|
// EntryType are the formats of lines in an mtree spec file
|
||||||
type EntryType int
|
type EntryType int
|
||||||
|
|
||||||
|
|
1
parse.go
1
parse.go
|
@ -93,6 +93,7 @@ func ParseSpec(r io.Reader) (*DirectoryHierarchy, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
e.Set = creator.curSet
|
||||||
default:
|
default:
|
||||||
// TODO(vbatts) log a warning?
|
// TODO(vbatts) log a warning?
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue