forked from mirrors/tar-split
tar/storage: work with raw (invalid utf8) names
When the entry name is not UTF-8, for example ISO-8859-1, then store the raw bytes. To accommodate this, we will have getters and setters for the entry's name now. Since this most heavily affects the json marshalling, we'll double check the sanity of the name before storing it in the JSONPacker.
This commit is contained in:
parent
39d06b9dc4
commit
032efafc29
3 changed files with 87 additions and 5 deletions
|
@ -6,6 +6,8 @@ import (
|
|||
"errors"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/vbatts/tar-split/tar/common"
|
||||
)
|
||||
|
||||
// ErrDuplicatePath occurs when a tar archive has more than one entry for the
|
||||
|
@ -61,7 +63,7 @@ func (jup *jsonUnpacker) Next() (*Entry, error) {
|
|||
|
||||
// check for dup name
|
||||
if e.Type == FileType {
|
||||
cName := filepath.Clean(e.Name)
|
||||
cName := filepath.Clean(e.GetName())
|
||||
if _, ok := jup.seen[cName]; ok {
|
||||
return nil, ErrDuplicatePath
|
||||
}
|
||||
|
@ -93,9 +95,17 @@ type jsonPacker struct {
|
|||
type seenNames map[string]struct{}
|
||||
|
||||
func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
|
||||
// if Name is not valid utf8, switch it to raw first.
|
||||
if e.Name != "" {
|
||||
if !common.IsValidUtf8String(e.Name) {
|
||||
e.NameRaw = []byte(e.Name)
|
||||
e.Name = ""
|
||||
}
|
||||
}
|
||||
|
||||
// check early for dup name
|
||||
if e.Type == FileType {
|
||||
cName := filepath.Clean(e.Name)
|
||||
cName := filepath.Clean(e.GetName())
|
||||
if _, ok := jp.seen[cName]; ok {
|
||||
return -1, ErrDuplicatePath
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue