local: fix filenames with invalid UTF-8 not being uploaded #568

This commit is contained in:
Nick Craig-Wood 2016-07-15 14:18:09 +01:00
parent 67562081f7
commit 9eeed25418

View File

@ -52,8 +52,8 @@ type Fs struct {
// Object represents a local filesystem object // Object represents a local filesystem object
type Object struct { type Object struct {
fs *Fs // The Fs this object is part of fs *Fs // The Fs this object is part of
remote string // The remote path remote string // The remote path - properly UTF-8 encoded - for rclone
path string // The local path path string // The local path - may not be properly UTF-8 encoded - for OS
info os.FileInfo // Interface for file info (always present) info os.FileInfo // Interface for file info (always present)
hashes map[fs.HashType]string // Hashes hashes map[fs.HashType]string // Hashes
} }
@ -70,7 +70,7 @@ func NewFs(name, root string) (fs.Fs, error) {
warned: make(map[string]struct{}), warned: make(map[string]struct{}),
nounc: nounc == "true", nounc: nounc == "true",
} }
f.root = f.filterPath(f.cleanUtf8(root)) f.root = f.filterPath(root)
// Check to see if this points to a file // Check to see if this points to a file
fi, err := os.Lstat(f.root) fi, err := os.Lstat(f.root)
@ -101,8 +101,8 @@ func (f *Fs) String() string {
// newObject makes a half completed Object // newObject makes a half completed Object
func (f *Fs) newObject(remote string) *Object { func (f *Fs) newObject(remote string) *Object {
remote = normString(remote) remote = normString(remote)
remote = filepath.ToSlash(remote) dstPath := f.filterPath(filepath.Join(f.root, remote))
dstPath := f.filterPath(filepath.Join(f.root, f.cleanUtf8(remote))) remote = filepath.ToSlash(f.cleanUtf8(remote))
return &Object{ return &Object{
fs: f, fs: f,
remote: remote, remote: remote,
@ -479,7 +479,7 @@ func (o *Object) String() string {
// Remote returns the remote path // Remote returns the remote path
func (o *Object) Remote() string { func (o *Object) Remote() string {
return o.fs.cleanUtf8(o.remote) return o.remote
} }
// Hash returns the requested hash of a file as a lowercase hex string // Hash returns the requested hash of a file as a lowercase hex string