jottacloud: fix for --fast-list

This commit is contained in:
albertony 2018-09-09 00:12:47 +02:00 committed by Nick Craig-Wood
parent f6ee0795ac
commit 1e7a7d756f

View file

@ -449,22 +449,27 @@ type listFileDirFn func(fs.DirEntry) error
// List the objects and directories into entries, from a // List the objects and directories into entries, from a
// special kind of JottaFolder representing a FileDirLis // special kind of JottaFolder representing a FileDirLis
func (f *Fs) listFileDir(rootPath string, root *api.JottaFolder, fn listFileDirFn) error { func (f *Fs) listFileDir(remoteStartPath string, startFolder *api.JottaFolder, fn listFileDirFn) error {
rootLen := len(rootPath) pathPrefix := "/" + f.filePathRaw("") // Non-escaped prefix of API paths to be cut off, to be left with the remote path including the remoteStartPath
for i := range root.Folders { pathPrefixLength := len(pathPrefix)
folder := &root.Folders[i] startPath := path.Join(pathPrefix, remoteStartPath) // Non-escaped API path up to and including remoteStartPath, to decide if it should be created as a new dir object
startPathLength := len(startPath)
for i := range startFolder.Folders {
folder := &startFolder.Folders[i]
if folder.Deleted { if folder.Deleted {
return nil return nil
} }
folderPath := path.Join(folder.Path, folder.Name) folderPath := path.Join(folder.Path, folder.Name)
remoteDirLength := len(folderPath) - pathPrefixLength
var remoteDir string var remoteDir string
subLen := len(folderPath) - rootLen if remoteDirLength > 0 {
if subLen > 0 { remoteDir = restoreReservedChars(folderPath[pathPrefixLength+1:])
remoteDir = restoreReservedChars(folderPath[rootLen+1:]) if remoteDirLength > startPathLength {
d := fs.NewDir(remoteDir, time.Time(folder.ModifiedAt)) d := fs.NewDir(remoteDir, time.Time(folder.ModifiedAt))
err := fn(d) err := fn(d)
if err != nil { if err != nil {
return err return err
}
} }
} }
for i := range folder.Files { for i := range folder.Files {
@ -525,9 +530,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
} }
return errors.Wrap(err, "couldn't list files") return errors.Wrap(err, "couldn't list files")
} }
rootPath := "/" + f.filePathRaw(dir)
list := walk.NewListRHelper(callback) list := walk.NewListRHelper(callback)
err = f.listFileDir(rootPath, &result, func(entry fs.DirEntry) error { err = f.listFileDir(dir, &result, func(entry fs.DirEntry) error {
return list.Add(entry) return list.Add(entry)
}) })
if err != nil { if err != nil {