1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 16:25:38 +00:00

Merge pull request #95 from vbatts/carry_pr87

entries: comment with keyword metadata
This commit is contained in:
Vincent Batts 2016-11-17 23:51:58 -05:00 committed by GitHub
commit b6ed8e415d
2 changed files with 27 additions and 4 deletions

9
tar.go
View file

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

22
walk.go
View file

@ -7,6 +7,7 @@ import (
"os/user" "os/user"
"path/filepath" "path/filepath"
"sort" "sort"
"strings"
"time" "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) { func Walk(root string, excludes []ExcludeFunc, keywords []Keyword) (*DirectoryHierarchy, error) {
creator := dhCreator{DH: &DirectoryHierarchy{}} creator := dhCreator{DH: &DirectoryHierarchy{}}
// insert signature and metadata comments first (user, machine, tree, date) // insert signature and metadata comments first (user, machine, tree, date)
metadataEntries := signatureEntries(root) for _, e := range signatureEntries(root) {
for _, e := range metadataEntries {
e.Pos = len(creator.DH.Entries) e.Pos = len(creator.DH.Entries)
creator.DH.Entries = append(creator.DH.Entries, e) 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 { err := startWalk(&creator, root, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
@ -356,3 +362,15 @@ func signatureEntries(root string) []Entry {
return sigEntries 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), ",")),
},
}
}