Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

build: modernize with "go fix -atomictypes": use sync/atomic types

Nick Craig-Wood77f9c70cf6a5
diff --git a/backend/azureblob/arrow.go b/backend/azureblob/arrow.go
index bb4619973..baaf51eb4 100644
--- a/backend/azureblob/arrow.go
+++ b/backend/azureblob/arrow.go
@@ -66,7 +66,7 @@ func (f *Fs) listArrowParallel(ctx context.Context, containerName, directory, pr
// Schedule every shard; SetLimit bounds concurrency, so more shards than
// workers gives free load balancing as workers pick up the next shard.
- var total int64
+ var total atomic.Int64
g, gCtx := errgroup.WithContext(ctx)
g.SetLimit(f.opt.ListParallelism)
for _, sh := range shards {
@@ -89,12 +89,12 @@ func (f *Fs) listArrowParallel(ctx context.Context, containerName, directory, pr
shardOpts.EndBefore = nil
}
n, err := f.listBlobsPager(gCtx, containerName, directory, prefix, addContainer, &shardOpts, delimiter, safeFn)
- atomic.AddInt64(&total, int64(n))
+ total.Add(int64(n))
return err
})
}
err := g.Wait()
- found := int(atomic.LoadInt64(&total))
+ found := int(total.Load())
if isEndBeforeUnsupported(err) {
// The account can't honour the shards' endBefore bounds, so parallel
// listing can't be used on it.
diff --git a/cmd/copyurl/copyurl_test.go b/cmd/copyurl/copyurl_test.go
index 1c4e32234..601650ae8 100644
--- a/cmd/copyurl/copyurl_test.go
+++ b/cmd/copyurl/copyurl_test.go
@@ -42,10 +42,10 @@ func TestRun_CallsCopyURL_WithExplicitFilename_Success(t *testing.T) {
tmp := t.TempDir()
dstPath := filepath.Join(tmp, "out.txt")
- var called int32
+ var called atomic.Int32
copyURL = func(_ctx context.Context, _dst fs.Fs, dstFileName, url string, auto, header, noclobber bool) (fs.Object, error) {
- atomic.AddInt32(&called, 1)
+ called.Add(1)
assert.Equal(t, "https://example.com/file", url)
assert.Equal(t, "out.txt", dstFileName)
assert.False(t, auto)
@@ -56,7 +56,7 @@ func TestRun_CallsCopyURL_WithExplicitFilename_Success(t *testing.T) {
err := run([]string{"https://example.com/file", dstPath})
require.NoError(t, err)
- assert.Equal(t, int32(1), atomic.LoadInt32(&called))
+ assert.Equal(t, int32(1), called.Load())
}
func TestRun_CallsCopyURL_WithAutoFilename_AndPropagatesError(t *testing.T) {
@@ -67,10 +67,10 @@ func TestRun_CallsCopyURL_WithAutoFilename_AndPropagatesError(t *testing.T) {
autoFilename = true
want := errors.New("boom")
- var called int32
+ var called atomic.Int32
copyURL = func(_ctx context.Context, _dst fs.Fs, dstFileName, url string, auto, header, noclobber bool) (fs.Object, error) {
- atomic.AddInt32(&called, 1)
+ called.Add(1)
assert.Equal(t, "", dstFileName) // auto filename -> empty
assert.True(t, auto)
return nil, want
@@ -79,7 +79,7 @@ func TestRun_CallsCopyURL_WithAutoFilename_AndPropagatesError(t *testing.T) {
err := run([]string{"https://example.com/auto/name", tmp})
require.Error(t, err)
assert.Equal(t, want, err)
- assert.Equal(t, int32(1), atomic.LoadInt32(&called))
+ assert.Equal(t, int32(1), called.Load())
}
func TestRunURLS_ErrorsWithStdoutAndWithPrintFilename(t *testing.T) {
@@ -115,12 +115,12 @@ func TestRunURLS_ProcessesCSV_ParallelCalls_AndAggregatesError(t *testing.T) {
// mock copyURL: succeed for /a and /b, fail for /c
- var calls int32
+ var calls atomic.Int32
var mu sync.Mutex
var seen []string
copyURL = func(_ctx context.Context, _dst fs.Fs, dstFileName, url string, auto, header, noclobber bool) (fs.Object, error) {
- atomic.AddInt32(&calls, 1)
+ calls.Add(1)
mu.Lock()
seen = append(seen, url+"|"+dstFileName)
mu.Unlock()
@@ -143,7 +143,7 @@ func TestRunURLS_ProcessesCSV_ParallelCalls_AndAggregatesError(t *testing.T) {
require.Error(t, err)
assert.Contains(t, err.Error(), "not all URLs copied successfully")
// 3 lines => 3 calls
- assert.Equal(t, int32(3), atomic.LoadInt32(&calls))
+ assert.Equal(t, int32(3), calls.Load())
// sanity: all expected URLs were seen
assert.ElementsMatch(t,