From ff0a299bfb4bbe9abb11b3f9dfdcf91a2a88b59c Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 31 Mar 2020 17:25:15 +0100 Subject: [PATCH] drive: don't delete files with multiple parents to avoid data loss Rclone can't safely delete files with multiple parents without PATCHing the parents list. This can be done, but since multiple parents are going away to be replaced by drive shortcuts we return an error for now. See #4013 --- backend/drive/drive.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 4007d2056..f47f79d2a 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -551,6 +551,7 @@ type baseObject struct { modifiedDate string // RFC3339 time it was last modified mimeType string // The object MIME type bytes int64 // size of the object + parents int // number of parents } type documentObject struct { baseObject @@ -1176,6 +1177,7 @@ func (f *Fs) newBaseObject(remote string, info *drive.File) baseObject { modifiedDate: modifiedDate, mimeType: info.MimeType, bytes: size, + parents: len(info.Parents), } } @@ -2989,6 +2991,9 @@ func (o *linkObject) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo // Remove an object func (o *baseObject) Remove(ctx context.Context) error { + if o.parents > 1 { + return errors.New("can't delete safely - has multiple parents") + } var err error err = o.fs.pacer.Call(func() (bool, error) { if o.fs.opt.UseTrash {