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 -minmax": use min and max builtins

Nick Craig-Woodb5bea683c56e
diff --git a/backend/huaweidrive/huaweidrive.go b/backend/huaweidrive/huaweidrive.go
index 3cda9077c..0e0f3a29c 100644
--- a/backend/huaweidrive/huaweidrive.go
+++ b/backend/huaweidrive/huaweidrive.go
@@ -1897,10 +1897,8 @@ func (o *Object) uploadResume(ctx context.Context, in io.Reader, leaf, directory
}
// Now upload the content in chunks
- chunkSize := int64(o.fs.opt.ChunkSize)
- if chunkSize < 256*1024 {
- chunkSize = 256 * 1024 // Minimum chunk size according to Huawei Drive API
- }
+ // Note 256k is the minimum chunk size according to Huawei Drive API
+ chunkSize := max(int64(o.fs.opt.ChunkSize), 256*1024)
if chunkSize > 64*1024*1024 {
chunkSize = 64 * 1024 * 1024 // Maximum single upload size
}
diff --git a/backend/iclouddrive/icloudphotos.go b/backend/iclouddrive/icloudphotos.go
index b3d80462c..dd26ba9ee 100644
--- a/backend/iclouddrive/icloudphotos.go
+++ b/backend/iclouddrive/icloudphotos.go
@@ -736,10 +736,7 @@ func (f *PhotosFs) ListR(ctx context.Context, dir string, callback fs.ListRCallb
}
close(jobCh)
- workers := fs.GetConfig(ctx).Checkers
- if len(jobs) < workers {
- workers = len(jobs)
- }
+ workers := min(len(jobs), fs.GetConfig(ctx).Checkers)
errs := make(chan error, workers)
for range workers {
diff --git a/fs/open_options.go b/fs/open_options.go
index 448cdd02a..4661cf1a2 100644
--- a/fs/open_options.go
+++ b/fs/open_options.go
@@ -125,13 +125,10 @@ func (o *RangeOption) Decode(size int64) (offset, limit int64) {
}
} else {
if o.End >= 0 {
- offset = size - o.End
- if offset < 0 {
- // RFC 7233 section 2.1: if the suffix-length is
- // larger than the representation, use the entire
- // representation.
- offset = 0
- }
+ // RFC 7233 section 2.1: if the suffix-length is
+ // larger than the representation, use the entire
+ // representation.
+ offset = max(size-o.End, 0)
} else {
offset = 0
}
@@ -168,13 +165,10 @@ func FixRangeOption(options []OpenOption, size int64) {
case *RangeOption:
// If start is < 0 then fetch from the end
if x.Start < 0 {
- start := size - x.End
- if start < 0 {
- // RFC 7233 section 2.1: if the suffix-length is
- // larger than the representation, use the entire
- // representation (#6310).
- start = 0
- }
+ // RFC 7233 section 2.1: if the suffix-length is
+ // larger than the representation, use the entire
+ // representation (#6310).
+ start := max(size-x.End, 0)
x = &RangeOption{Start: start, End: -1}
options[i] = x
}
diff --git a/lib/rest/headers.go b/lib/rest/headers.go
index f3bd6bf30..fcbbe69cb 100644
--- a/lib/rest/headers.go
+++ b/lib/rest/headers.go
@@ -126,10 +126,7 @@ func CheckContentRange(resp *http.Response, options []fs.OpenOption, size int64)
expectedEnd = rangeSize - 1
}
} else if rangeSize >= 0 {
- expectedStart = rangeSize - requested.End
- if expectedStart < 0 {
- expectedStart = 0
- }
+ expectedStart = max(rangeSize-requested.End, 0)
expectedEnd = rangeSize - 1
}