drive: fix single Drive Document as FS root

Allow using Drive Documents as FS root by doing a direcoty list during NewFS.

Fixes #1772
This commit is contained in:
Fabian Möller 2018-01-25 15:39:03 +01:00 committed by Nick Craig-Wood
parent 1f5e23aedb
commit 29286cc8b3

View File

@ -507,14 +507,20 @@ func NewFs(name, path string) (fs.Fs, error) {
// No root so return old f // No root so return old f
return f, nil return f, nil
} }
_, err := newF.newObjectWithInfo(remote, nil) entries, err := newF.List("")
if err != nil { if err != nil {
// File doesn't exist so return old f // unable to list folder so return old f
return f, nil return f, nil
} }
for _, e := range entries {
if _, isObject := e.(fs.Object); isObject && e.Remote() == remote {
// return an error with an fs which points to the parent // return an error with an fs which points to the parent
return &newF, fs.ErrorIsFile return &newF, fs.ErrorIsFile
} }
}
// File doesn't exist so return old f
return f, nil
}
// fmt.Printf("Root id %s", f.dirCache.RootID()) // fmt.Printf("Root id %s", f.dirCache.RootID())
return f, nil return f, nil
} }