forked from mirrors/tar-split
tar/storage: use filepath
instead of path
This commit is contained in:
parent
6d59e7bc76
commit
c2c2dde4cb
2 changed files with 9 additions and 10 deletions
|
@ -7,23 +7,23 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileGetter is the interface for getting a stream of a file payload, address
|
// FileGetter is the interface for getting a stream of a file payload, address
|
||||||
// by name/filepath. Presumably, the names will be scoped to relative file
|
// by name/filename. Presumably, the names will be scoped to relative file
|
||||||
// paths.
|
// paths.
|
||||||
type FileGetter interface {
|
type FileGetter interface {
|
||||||
// Get returns a stream for the provided file path
|
// Get returns a stream for the provided file path
|
||||||
Get(filepath string) (output io.ReadCloser, err error)
|
Get(filename string) (output io.ReadCloser, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilePutter is the interface for storing a stream of a file payload,
|
// FilePutter is the interface for storing a stream of a file payload,
|
||||||
// addressed by name/filepath.
|
// addressed by name/filename.
|
||||||
type FilePutter interface {
|
type FilePutter interface {
|
||||||
// Put returns the size of the stream received, and the crc64 checksum for
|
// Put returns the size of the stream received, and the crc64 checksum for
|
||||||
// the provided stream
|
// the provided stream
|
||||||
Put(filepath string, input io.Reader) (size int64, checksum []byte, err error)
|
Put(filename string, input io.Reader) (size int64, checksum []byte, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileGetPutter is the interface that groups both Getting and Putting file
|
// FileGetPutter is the interface that groups both Getting and Putting file
|
||||||
|
@ -44,8 +44,7 @@ type pathFileGetter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pfg pathFileGetter) Get(filename string) (io.ReadCloser, error) {
|
func (pfg pathFileGetter) Get(filename string) (io.ReadCloser, error) {
|
||||||
// FIXME might should have a check for '../../../../etc/passwd' attempts?
|
return os.Open(filepath.Join(pfg.root, filename))
|
||||||
return os.Open(path.Join(pfg.root, filename))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type bufferFileGetPutter struct {
|
type bufferFileGetPutter struct {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrDuplicatePath is occured when a tar archive has more than one entry for
|
// ErrDuplicatePath is occured when a tar archive has more than one entry for
|
||||||
|
@ -61,7 +61,7 @@ func (jup *jsonUnpacker) Next() (*Entry, error) {
|
||||||
|
|
||||||
// check for dup name
|
// check for dup name
|
||||||
if e.Type == FileType {
|
if e.Type == FileType {
|
||||||
cName := path.Clean(e.Name)
|
cName := filepath.Clean(e.Name)
|
||||||
if _, ok := jup.seen[cName]; ok {
|
if _, ok := jup.seen[cName]; ok {
|
||||||
return nil, ErrDuplicatePath
|
return nil, ErrDuplicatePath
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ const emptyByte byte = 0
|
||||||
func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
|
func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
|
||||||
// check early for dup name
|
// check early for dup name
|
||||||
if e.Type == FileType {
|
if e.Type == FileType {
|
||||||
cName := path.Clean(e.Name)
|
cName := filepath.Clean(e.Name)
|
||||||
if _, ok := jp.seen[cName]; ok {
|
if _, ok := jp.seen[cName]; ok {
|
||||||
return -1, ErrDuplicatePath
|
return -1, ErrDuplicatePath
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue