1
mirror of https://github.com/rclone/rclone synced 2024-12-26 18:23:45 +01:00

drive: Don't return nil Object with nil error from newObject* functions.

Before this change the newObject* functions could return object=nil
with err=nil.  The result of these functions are passed outside of the
backend code (eg in Copy, Move) and returning a nil object with a nil
error leads to crashes elsewhere as it breaks expectations.

After this change we return (nil, fs.ErrorObjectNotFound) in these
cases. The one place this is actually needd internally (when turning
items into listings) we detect that error and use it to mean skip the
directory item.

This problem was noticed while testing the shortcuts code. It
shouldn't happen normally but it is conceivable it could.
This commit is contained in:
Nick Craig-Wood 2020-04-24 10:01:06 +01:00
parent ba7f7c8319
commit 2f5a2d3c48

View File

@ -1281,16 +1281,16 @@ func (f *Fs) newObjectWithExportInfo(
return f.newRegularObject(remote, info), nil
case f.opt.SkipGdocs:
fs.Debugf(remote, "Skipping google document type %q", info.MimeType)
return nil, nil
return nil, fs.ErrorObjectNotFound
default:
// If item MimeType is in the ExportFormats then it is a google doc
if !isDocument {
fs.Debugf(remote, "Ignoring unknown document type %q", info.MimeType)
return nil, nil
return nil, fs.ErrorObjectNotFound
}
if extension == "" {
fs.Debugf(remote, "No export formats found for %q", info.MimeType)
return nil, nil
return nil, fs.ErrorObjectNotFound
}
if isLinkMimeType(exportMimeType) {
return f.newLinkObject(remote, info, extension, exportMimeType)
@ -1801,7 +1801,11 @@ func (f *Fs) itemToDirEntry(remote string, item *drive.File) (fs.DirEntry, error
case f.opt.AuthOwnerOnly && !isAuthOwned(item):
// ignore object
default:
return f.newObjectWithInfo(remote, item)
entry, err = f.newObjectWithInfo(remote, item)
if err == fs.ErrorObjectNotFound {
return nil, nil
}
return entry, err
}
return nil, nil
}