forked from TrueCloudLab/rclone
Fix oddities using a file in the root - fixes #471
* Check return from NewFsObject which caused nil ptr deref * Correct root directory from "" to string(os.PathSeparator) in getDirFile
This commit is contained in:
parent
bdd26d71b2
commit
d205dc23e9
1 changed files with 8 additions and 1 deletions
|
@ -77,6 +77,9 @@ func NewFs(name, root string) (fs.Fs, error) {
|
||||||
var remote string
|
var remote string
|
||||||
f.root, remote = getDirFile(f.root)
|
f.root, remote = getDirFile(f.root)
|
||||||
obj := f.NewFsObject(remote)
|
obj := f.NewFsObject(remote)
|
||||||
|
if obj == nil {
|
||||||
|
return nil, fmt.Errorf("Failed to make object for %q in %q", remote, f.root)
|
||||||
|
}
|
||||||
// return a Fs Limited to this object
|
// return a Fs Limited to this object
|
||||||
return fs.NewLimited(f, obj), nil
|
return fs.NewLimited(f, obj), nil
|
||||||
}
|
}
|
||||||
|
@ -622,7 +625,11 @@ func (o *Object) Remove() error {
|
||||||
// Assumes os.PathSeparator is used.
|
// Assumes os.PathSeparator is used.
|
||||||
func getDirFile(s string) (string, string) {
|
func getDirFile(s string) (string, string) {
|
||||||
i := strings.LastIndex(s, string(os.PathSeparator))
|
i := strings.LastIndex(s, string(os.PathSeparator))
|
||||||
return s[:i], s[i+1:]
|
dir, file := s[:i], s[i+1:]
|
||||||
|
if dir == "" {
|
||||||
|
dir = string(os.PathSeparator)
|
||||||
|
}
|
||||||
|
return dir, file
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) filterPath(s string) string {
|
func (f *Fs) filterPath(s string) string {
|
||||||
|
|
Loading…
Add table
Reference in a new issue