"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
pikpak: add file name integrity check during upload
wiserainca6631746a7a
diff --git a/backend/pikpak/pikpak.go b/backend/pikpak/pikpak.goindex 8470928e7..e8638af39 100644--- a/backend/pikpak/pikpak.go+++ b/backend/pikpak/pikpak.go@@ -1508,15 +1508,6 @@ func (f *Fs) upload(ctx context.Context, in io.Reader, leaf, dirID, gcid string,}if new.File == nil {return nil, fmt.Errorf("invalid response: %+v", new)- } else if new.File.Phase == api.PhaseTypeComplete {- // early return; in case of zero-byte objects- if acc, ok := in.(*accounting.Account); ok && acc != nil {- // if `in io.Reader` is still in type of `*accounting.Account` (meaning that it is unused)- // it is considered as a server side copy as no incoming/outgoing traffic occur at all- acc.ServerSideTransferStart()- acc.ServerSideCopyEnd(size)- }- return new.File, nil}defer atexit.OnError(&err, func() {@@ -1524,13 +1515,32 @@ func (f *Fs) upload(ctx context.Context, in io.Reader, leaf, dirID, gcid string,if cancelErr := f.deleteObjects(ctx, []string{new.File.ID}, false); cancelErr != nil {fs.Logf(leaf, "failed to cancel upload: %v", cancelErr)}- if cancelErr := f.deleteTask(ctx, new.Task.ID, false); cancelErr != nil {- fs.Logf(leaf, "failed to cancel upload: %v", cancelErr)+ if new.Task != nil {+ if cancelErr := f.deleteTask(ctx, new.Task.ID, false); cancelErr != nil {+ fs.Logf(leaf, "failed to cancel upload: %v", cancelErr)+ }+ fs.Debugf(leaf, "waiting %v for the cancellation to be effective", taskWaitTime)+ time.Sleep(taskWaitTime)}- fs.Debugf(leaf, "waiting %v for the cancellation to be effective", taskWaitTime)- time.Sleep(taskWaitTime)})()+ // Note: The API might automatically append a numbered suffix to the filename,+ // even if a file with the same name does not exist in the target directory.+ if upName := f.opt.Enc.ToStandardName(new.File.Name); leaf != upName {+ return nil, fserrors.NoRetryError(fmt.Errorf("uploaded file name mismatch: expected %q, got %q", leaf, upName))+ }++ // early return; in case of zero-byte objects or uploaded by matched gcid+ if new.File.Phase == api.PhaseTypeComplete {+ if acc, ok := in.(*accounting.Account); ok && acc != nil {+ // if `in io.Reader` is still in type of `*accounting.Account` (meaning that it is unused)+ // it is considered as a server side copy as no incoming/outgoing traffic occur at all+ acc.ServerSideTransferStart()+ acc.ServerSideCopyEnd(size)+ }+ return new.File, nil+ }+if uploadType == api.UploadTypeForm && new.Form != nil {err = f.uploadByForm(ctx, in, req.Name, size, new.Form, options...)} else if uploadType == api.UploadTypeResumable && new.Resumable != nil {@@ -1542,6 +1552,9 @@ func (f *Fs) upload(ctx context.Context, in io.Reader, leaf, dirID, gcid string,if err != nil {return nil, fmt.Errorf("failed to upload: %w", err)}+ if new.Task == nil {+ return new.File, nil+ }return new.File, f.waitTask(ctx, new.Task.ID)}