copy: avoid deletion error messages when aborting multi-thread copies

When doing a multi-thread copy, handling of the partial upload removal is already done in ChunkWriter.Abort. We can thus avoid doing it on exit in this case, especially as error messages would get generated in most cases (file still being written to or doesn't yet exist)
This commit is contained in:
Jonathan Giannuzzi 2025-01-20 12:57:42 +00:00 committed by Jonathan Giannuzzi
parent bd5f6e969b
commit 14a149da42
1 changed files with 10 additions and 8 deletions

View File

@ -230,14 +230,6 @@ func (c *copy) updateOrPut(ctx context.Context, in io.ReadCloser, uploadOptions
// Do a manual copy by reading the bytes and writing them
func (c *copy) manualCopy(ctx context.Context) (actionTaken string, newDst fs.Object, err error) {
// Remove partial files on premature exit
if !c.inplace {
defer atexit.Unregister(atexit.Register(func() {
ctx := context.Background()
c.removeFailedPartialCopy(ctx, c.f, c.remoteForCopy)
}))
}
// Options for the upload
uploadOptions := []fs.OpenOption{c.hashOption}
for _, option := range c.ci.UploadHeaders {
@ -253,10 +245,20 @@ func (c *copy) manualCopy(ctx context.Context) (actionTaken string, newDst fs.Ob
downloadOptions = append(downloadOptions, option)
}
// Do multi-thread copy if possible
if doMultiThreadCopy(ctx, c.f, c.src) {
return c.multiThreadCopy(ctx, uploadOptions)
}
// Remove partial files on premature exit
// This is not needed for inplace and/or multi-threaded copies
if !c.inplace {
defer atexit.Unregister(atexit.Register(func() {
ctx := context.Background()
c.removeFailedPartialCopy(ctx, c.f, c.remoteForCopy)
}))
}
var in io.ReadCloser
in, err = Open(ctx, c.src, downloadOptions...)
if err != nil {