From 519623d9f181cffd4125725409adce9dbaea5a1e Mon Sep 17 00:00:00 2001 From: Vikas Bhansali <64532198+vibhansa-msft@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:11:42 +0530 Subject: [PATCH] azurefiles: Fix server side copy not waiting for completion - fixes #8848 --- backend/azurefiles/azurefiles.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/azurefiles/azurefiles.go b/backend/azurefiles/azurefiles.go index a9fed6e2b..59fe21a51 100644 --- a/backend/azurefiles/azurefiles.go +++ b/backend/azurefiles/azurefiles.go @@ -1313,10 +1313,29 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, } srcURL := srcObj.fileClient().URL() fc := f.fileClient(remote) - _, err = fc.StartCopyFromURL(ctx, srcURL, &opt) + startCopy, err := fc.StartCopyFromURL(ctx, srcURL, &opt) if err != nil { return nil, fmt.Errorf("Copy failed: %w", err) } + + // Poll for completion if necessary + // + // The for loop is never executed for same storage account copies. + copyStatus := startCopy.CopyStatus + var properties file.GetPropertiesResponse + pollTime := 100 * time.Millisecond + + for copyStatus != nil && string(*copyStatus) == string(file.CopyStatusTypePending) { + time.Sleep(pollTime) + + properties, err = fc.GetProperties(ctx, &file.GetPropertiesOptions{}) + if err != nil { + return nil, err + } + copyStatus = properties.CopyStatus + pollTime = min(2*pollTime, time.Second) + } + dstObj, err := f.NewObject(ctx, remote) if err != nil { return nil, fmt.Errorf("Copy: NewObject failed: %w", err)