Skip to content

Commit 43a6346

Browse files
committed
internxt: fix pre-upload file existence check and enhance backup file deletion process in Update method
1 parent 4149392 commit 43a6346

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

backend/internxt/internxt.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func (f *Fs) preUploadCheck(ctx context.Context, leaf, directoryID string) (*fol
447447
return nil, nil
448448
}
449449

450-
if len(checkResult.Files) > 0 && checkResult.Files[0].Exists {
450+
if len(checkResult.Files) > 0 && checkResult.Files[0].FileExists() {
451451
existingUUID := checkResult.Files[0].UUID
452452
if existingUUID != "" {
453453
fileMeta, err := files.GetFileMeta(ctx, f.cfg, existingUUID)
@@ -460,7 +460,6 @@ func (f *Fs) preUploadCheck(ctx context.Context, leaf, directoryID string) (*fol
460460
}
461461
}
462462
}
463-
464463
return nil, nil
465464
}
466465

@@ -854,6 +853,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
854853
}
855854
fs.Debugf(o.f, "Upload failed, successfully restored backup file to original name")
856855
}
856+
return err
857857
}
858858

859859
// Update object metadata
@@ -864,6 +864,22 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
864864
o.size = 0
865865
}
866866

867+
// Step 3: Upload succeeded - delete the backup file
868+
if backupUUID != "" {
869+
fs.Debugf(o.f, "Upload succeeded, deleting backup file %s.%s (UUID: %s)", backupName, backupType, backupUUID)
870+
err := o.f.pacer.Call(func() (bool, error) {
871+
err := files.DeleteFile(ctx, o.f.cfg, backupUUID)
872+
return shouldRetry(ctx, err)
873+
})
874+
if err != nil {
875+
fs.Errorf(o.f, "Failed to delete backup file %s.%s (UUID: %s): %v. This may leave an orphaned backup file.",
876+
backupName, backupType, backupUUID, err)
877+
// Don't fail the upload just because backup deletion failed
878+
} else {
879+
fs.Debugf(o.f, "Successfully deleted backup file")
880+
}
881+
}
882+
867883
return nil
868884
}
869885

0 commit comments

Comments
 (0)