1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-07-04 06:38:30 +00:00

*: have gomtree always evaluate tar_time if it is present

if the keyword "tar_time" is present when evaluating
an Entry, gomtree should use the tar_time when evaluating
the "time" keyword as well. This commit also adds a test that
makes sure "tar_time" wins against "time" if both are present.
Some minor clean-ups as well, such as checking if KeywordFunc[keyword]
actually retrieves a function.

Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
Stephen Chung 2016-07-22 18:01:54 -04:00
parent bc6f3bf902
commit 656e577ecc
7 changed files with 106 additions and 25 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"sort"
"strings"
)
// Result of a Check
@ -66,7 +67,15 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
}
for _, kv := range kvs {
keywordFunc, ok := KeywordFuncs[kv.Keyword()]
kw := kv.Keyword()
// 'tar_time' keyword evaluation wins against 'time' keyword evaluation
if kv.Keyword() == "time" && inSlice("tar_time", keywords) {
kw = "tar_time"
tartime := fmt.Sprintf("%s.%s", (strings.Split(kv.Value(), ".")[0]), "000000000")
kv = KeyVal(KeyVal(kw).ChangeValue(tartime))
}
keywordFunc, ok := KeywordFuncs[kw]
if !ok {
return nil, fmt.Errorf("Unknown keyword %q for file %q", kv.Keyword(), e.Path())
}