File fix_var_scope.patch of Package rclone

From 28a3bf66a2dda40473f644198be608ad8372ba1b Mon Sep 17 00:00:00 2001
From: Ralf Haferkamp <r.haferkamp@opencloud.eu>
Date: Tue, 1 Apr 2025 11:29:02 +0200
Subject: [PATCH] fix: tus upload using wrong upload URL

Don't misuse the Fs struct for returning the TUS upload location. The
Fs struct is shared for the whole session, but the upload location
varies per Upload. Using the Fs struct caused different Upload of
overwrite each other's upload location.
---
 backend/webdav/tus.go | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/backend/webdav/tus.go b/backend/webdav/tus.go
index 066bc949e4194..3f6a843bbbd73 100644
--- a/backend/webdav/tus.go
+++ b/backend/webdav/tus.go
@@ -42,20 +42,20 @@ func (o *Object) updateViaTus(ctx context.Context, in io.Reader, contentType str
 	return err
 }
 
-func (f *Fs) shouldRetryCreateUpload(ctx context.Context, resp *http.Response, err error) (bool, error) {
+func (f *Fs) getTusLocationOrRetry(ctx context.Context, resp *http.Response, err error) (bool, string, error) {
 
 	switch resp.StatusCode {
 	case 201:
 		location := resp.Header.Get("Location")
-		f.chunksUploadURL = location
-		return false, nil
+		return false, location, nil
 	case 412:
-		return false, ErrVersionMismatch
+		return false, "", ErrVersionMismatch
 	case 413:
-		return false, ErrLargeUpload
+		return false, "", ErrLargeUpload
 	}
 
-	return f.shouldRetry(ctx, resp, err)
+	retry, err := f.shouldRetry(ctx, resp, err)
+	return retry, "", err
 }
 
 // CreateUploader creates a new upload to the server.
@@ -90,16 +90,19 @@ func (o *Object) CreateUploader(ctx context.Context, u *Upload, options ...fs.Op
 	opts.ExtraHeaders["Tus-Resumable"] = "1.0.0"
 	// opts.ExtraHeaders["mtime"] = strconv.FormatInt(src.ModTime(ctx).Unix(), 10)
 
+	var tusLocation string
 	// rclone http call
 	err := o.fs.pacer.CallNoRetry(func() (bool, error) {
+		var retry bool
 		res, err := o.fs.srv.Call(ctx, &opts)
-		return o.fs.shouldRetryCreateUpload(ctx, res, err)
+		retry, tusLocation, err = o.fs.getTusLocationOrRetry(ctx, res, err)
+		return retry, err
 	})
 	if err != nil {
 		return nil, fmt.Errorf("making upload directory failed: %w", err)
 	}
 
-	uploader := NewUploader(o.fs, o.fs.chunksUploadURL, u, 0)
+	uploader := NewUploader(o.fs, tusLocation, u, 0)
 
 	return uploader, nil
 }
openSUSE Build Service is sponsored by