From 2f5a2d3c48ba4b0ce6ea8d8eb0970189c656ce84 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 24 Apr 2020 10:01:06 +0100 Subject: [PATCH] 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. --- backend/drive/drive.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index f47f79d2a..5ac8f3f7e 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -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 }