entries: comment with keyword metadata

Since not every keyword applies to every type entry, include a comment
with the keywords the manifest was generated with.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Aleksa Sarai 2016-11-12 15:03:20 +11:00 committed by Vincent Batts
parent a6df651d88
commit 408b615c3c
2 changed files with 27 additions and 4 deletions

9
tar.go
View File

@ -82,8 +82,13 @@ func (ts *tarStream) readHeaders() {
Set: nil,
Keywords: []KeyVal{"type=dir"},
}
metadataEntries := signatureEntries("<user specified tar archive>")
for _, e := range metadataEntries {
// insert signature and metadata comments first (user, machine, tree, date)
for _, e := range signatureEntries("<user specified tar archive>") {
e.Pos = len(ts.creator.DH.Entries)
ts.creator.DH.Entries = append(ts.creator.DH.Entries, e)
}
// insert keyword metadata next
for _, e := range keywordEntries(ts.keywords) {
e.Pos = len(ts.creator.DH.Entries)
ts.creator.DH.Entries = append(ts.creator.DH.Entries, e)
}

22
walk.go
View File

@ -7,6 +7,7 @@ import (
"os/user"
"path/filepath"
"sort"
"strings"
"time"
)
@ -28,11 +29,16 @@ var defaultSetKeywords = []KeyVal{"type=file", "nlink=1", "flags=none", "mode=06
func Walk(root string, excludes []ExcludeFunc, keywords []Keyword) (*DirectoryHierarchy, error) {
creator := dhCreator{DH: &DirectoryHierarchy{}}
// insert signature and metadata comments first (user, machine, tree, date)
metadataEntries := signatureEntries(root)
for _, e := range metadataEntries {
for _, e := range signatureEntries(root) {
e.Pos = len(creator.DH.Entries)
creator.DH.Entries = append(creator.DH.Entries, e)
}
// insert keyword metadata next
for _, e := range keywordEntries(keywords) {
e.Pos = len(creator.DH.Entries)
creator.DH.Entries = append(creator.DH.Entries, e)
}
// walk the directory and add entries
err := startWalk(&creator, root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
@ -356,3 +362,15 @@ func signatureEntries(root string) []Entry {
return sigEntries
}
// keywordEntries returns a slice of entries including a comment of the
// keywords requested when generating this manifest.
func keywordEntries(keywords []Keyword) []Entry {
// Convert all of the keywords to zero-value keyvals.
return []Entry{
{
Type: CommentType,
Raw: fmt.Sprintf("#%16s%s", "keywords: ", strings.Join(FromKeywords(keywords), ",")),
},
}
}