diff --git a/tar.go b/tar.go index 8165841..8d9e0dd 100644 --- a/tar.go +++ b/tar.go @@ -82,8 +82,13 @@ func (ts *tarStream) readHeaders() { Set: nil, Keywords: []KeyVal{"type=dir"}, } - metadataEntries := signatureEntries("") - for _, e := range metadataEntries { + // insert signature and metadata comments first (user, machine, tree, date) + for _, e := range signatureEntries("") { + 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) } diff --git a/walk.go b/walk.go index 5209d6e..7f5b171 100644 --- a/walk.go +++ b/walk.go @@ -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), ",")), + }, + } +}