vis: refactored code to reflect using vis/unvis for file names

Added some more test cases for `vis`ing and `unvis`ing
strings, and a test case that walks/checks a directory with
filenames that require encoding. Had to change Path() to account
for possible errors Unvis() could return. Refactored Vis()/Unvis() into
go-mtree tar functionality as well.

Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
Stephen Chung 2016-07-20 21:18:27 -04:00
parent a63f83d94d
commit 773763fb87
12 changed files with 177 additions and 41 deletions

23
tar.go
View file

@ -97,8 +97,15 @@ func (ts *tarStream) readHeaders() {
defer os.Remove(tmpFile.Name())
// Alright, it's either file or directory
encodedName, err := Vis(filepath.Base(hdr.Name))
if err != nil {
tmpFile.Close()
os.Remove(tmpFile.Name())
ts.pipeReader.CloseWithError(err)
return
}
e := Entry{
Name: filepath.Base(hdr.Name),
Name: encodedName,
Type: RelativeType,
}
@ -213,8 +220,13 @@ func populateTree(root, e *Entry, hdr *tar.Header, ts *tarStream) {
if isDir {
newEntry = e
} else {
encodedName, err := Vis(name)
if err != nil {
ts.setErr(err)
return
}
newEntry = &Entry{
Name: name,
Name: encodedName,
Type: RelativeType,
}
}
@ -230,8 +242,13 @@ func populateTree(root, e *Entry, hdr *tar.Header, ts *tarStream) {
parent.Children = append([]*Entry{e}, parent.Children...)
e.Parent = parent
} else {
commentpath, err := e.Path()
if err != nil {
ts.setErr(err)
return
}
commentEntry := Entry{
Raw: "# " + e.Path(),
Raw: "# " + commentpath,
Type: CommentType,
}
e.Prev = &commentEntry