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: use sequence Split introduced in go1.24

Nick Craig-Wood71b9b4ad7a37
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index 6977ff2d7..81503a54e 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -684,7 +684,7 @@ func (f *Fs) rcFetch(ctx context.Context, in rc.Params) (rc.Params, error) {
start, end int64
}
parseChunks := func(ranges string) (crs []chunkRange, err error) {
- for _, part := range strings.Split(ranges, ",") {
+ for part := range strings.SplitSeq(ranges, ",") {
var start, end int64 = 0, math.MaxInt64
switch ints := strings.Split(part, ":"); len(ints) {
case 1:
diff --git a/backend/doi/link_header.go b/backend/doi/link_header.go
index 423ea8d89..c05ebcfd8 100644
--- a/backend/doi/link_header.go
+++ b/backend/doi/link_header.go
@@ -18,7 +18,7 @@ type headerLink struct {
}
func parseLinkHeader(header string) (links []headerLink) {
- for _, link := range strings.Split(header, ",") {
+ for link := range strings.SplitSeq(header, ",") {
link = strings.TrimSpace(link)
parsed := parseLink(link)
if parsed != nil {
@@ -30,7 +30,7 @@ func parseLinkHeader(header string) (links []headerLink) {
func parseLink(link string) (parsedLink *headerLink) {
var parts []string
- for _, part := range strings.Split(link, ";") {
+ for part := range strings.SplitSeq(link, ";") {
parts = append(parts, strings.TrimSpace(part))
}
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index 388444aad..5b25f0c0a 100644
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -191,7 +191,7 @@ func driveScopes(scopesString string) (scopes []string) {
if scopesString == "" {
scopesString = defaultScope
}
- for _, scope := range strings.Split(scopesString, ",") {
+ for scope := range strings.SplitSeq(scopesString, ",") {
scope = strings.TrimSpace(scope)
scopes = append(scopes, scopePrefix+scope)
}
@@ -1220,7 +1220,7 @@ func isLinkMimeType(mimeType string) bool {
// into a list of unique extensions with leading "." and a list of associated MIME types
func parseExtensions(extensionsIn ...string) (extensions, mimeTypes []string, err error) {
for _, extensionText := range extensionsIn {
- for _, extension := range strings.Split(extensionText, ",") {
+ for extension := range strings.SplitSeq(extensionText, ",") {
extension = strings.ToLower(strings.TrimSpace(extension))
if extension == "" {
continue
diff --git a/backend/mailru/mailru.go b/backend/mailru/mailru.go
index d304bb8a3..52695400d 100644
--- a/backend/mailru/mailru.go
+++ b/backend/mailru/mailru.go
@@ -400,7 +400,7 @@ type quirks struct {
}
func (q *quirks) parseQuirks(option string) {
- for _, flag := range strings.Split(option, ",") {
+ for flag := range strings.SplitSeq(option, ",") {
switch strings.ToLower(strings.TrimSpace(flag)) {
case "binlist":
// The official client sometimes uses a so called "bin" protocol,
@@ -1770,7 +1770,7 @@ func (f *Fs) parseSpeedupPatterns(patternString string) (err error) {
f.speedupAny = false
uniqueValidPatterns := make(map[string]any)
- for _, pattern := range strings.Split(patternString, ",") {
+ for pattern := range strings.SplitSeq(patternString, ",") {
pattern = strings.ToLower(strings.TrimSpace(pattern))
if pattern == "" {
continue
diff --git a/backend/webdav/api/types.go b/backend/webdav/api/types.go
index cef1cd701..d49064050 100644
--- a/backend/webdav/api/types.go
+++ b/backend/webdav/api/types.go
@@ -123,7 +123,7 @@ func (p *Prop) Hashes() (hashes map[hash.Type]string) {
hashes = make(map[hash.Type]string)
for _, checksums := range p.Checksums {
checksums = strings.ToLower(checksums)
- for _, checksum := range strings.Split(checksums, " ") {
+ for checksum := range strings.SplitSeq(checksums, " ") {
switch {
case strings.HasPrefix(checksum, "sha1:"):
hashes[hash.SHA1] = checksum[5:]
diff --git a/bin/not-in-stable.go b/bin/not-in-stable.go
index 5f988af82..2981835b7 100644
--- a/bin/not-in-stable.go
+++ b/bin/not-in-stable.go
@@ -33,7 +33,7 @@ func readCommits(from, to string) (logMap map[string]string, logs []string) {
}
logMap = map[string]string{}
logs = []string{}
- for _, line := range bytes.Split(out, []byte{'\n'}) {
+ for line := range bytes.SplitSeq(out, []byte{'\n'}) {
if len(line) == 0 {
continue
}
diff --git a/cmd/bisync/bisync_test.go b/cmd/bisync/bisync_test.go
index 0fc680e82..f7c05d5e8 100644
--- a/cmd/bisync/bisync_test.go
+++ b/cmd/bisync/bisync_test.go
@@ -522,7 +522,7 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
require.NoError(b.t, err)
b.step = 0
b.stopped = false
- for _, line := range strings.Split(string(scenBuf), "\n") {
+ for line := range strings.SplitSeq(string(scenBuf), "\n") {
comment := strings.Index(line, "#")
if comment != -1 {
line = line[:comment]
@@ -936,7 +936,7 @@ func (b *bisyncTest) runTestStep(ctx context.Context, line string) (err error) {
// splitLine splits scenario line into tokens and performs
// substitutions that involve whitespace or control chars.
func splitLine(line string) (args []string) {
- for _, s := range strings.Fields(line) {
+ for s := range strings.FieldsSeq(line) {
b := []byte(whitespaceReplacer.Replace(s))
b = regexChar.ReplaceAllFunc(b, func(b []byte) []byte {
c, _ := strconv.ParseUint(string(b[5:7]), 16, 8)
@@ -1513,7 +1513,7 @@ func (b *bisyncTest) compareResults() int {
fs.Log(nil, divider)
fs.Logf(nil, color(terminal.RedFg, "| MISCOMPARE -Golden vs +Results for %s"), file)
- for _, line := range strings.Split(strings.TrimSpace(text), "\n") {
+ for line := range strings.SplitSeq(strings.TrimSpace(text), "\n") {
fs.Logf(nil, "| %s", strings.TrimSpace(line))
}
}
diff --git a/cmd/bisync/compare.go b/cmd/bisync/compare.go
index cf69b5d1c..9334bec7f 100644
--- a/cmd/bisync/compare.go
+++ b/cmd/bisync/compare.go
@@ -219,8 +219,8 @@ func (b *bisyncRun) setFromCompareFlag(ctx context.Context) error {
return nil
}
var CompareFlag CompareOpt // for exclusions
- opts := strings.Split(b.opt.CompareFlag, ",")
- for _, opt := range opts {
+ opts := strings.SplitSeq(b.opt.CompareFlag, ",")
+ for opt := range opts {
switch strings.ToLower(strings.TrimSpace(opt)) {
case "size":
b.opt.Compare.Size = true
diff --git a/cmd/help.go b/cmd/help.go
index ff449b8c8..a99f54ce9 100644
--- a/cmd/help.go
+++ b/cmd/help.go
@@ -344,7 +344,7 @@ func showBackend(name string) {
}
for _, ex := range opt.Examples {
fmt.Printf(" - %s\n", quoteString(ex.Value))
- for _, line := range strings.Split(ex.Help, "\n") {
+ for line := range strings.SplitSeq(ex.Help, "\n") {
fmt.Printf(" - %s\n", line)
}
}
diff --git a/cmd/serve/proxy/proxy.go b/cmd/serve/proxy/proxy.go
index 7acc0ce7a..efe2fb459 100644
--- a/cmd/serve/proxy/proxy.go
+++ b/cmd/serve/proxy/proxy.go
@@ -182,7 +182,7 @@ func (p *Proxy) run(in map[string]string) (config configmap.Simple, err error) {
// Obscure any values in the config map that need it
obscureFields, ok := config.Get("_obscure")
if ok {
- for _, key := range strings.Split(obscureFields, ",") {
+ for key := range strings.SplitSeq(obscureFields, ",") {
value, ok := config.Get(key)
if ok {
obscuredValue, err := obscure.Obscure(value)
diff --git a/cmd/test/info/internal/internal.go b/cmd/test/info/internal/internal.go
index 7af06b87a..ce06bbe2f 100644
--- a/cmd/test/info/internal/internal.go
+++ b/cmd/test/info/internal/internal.go
@@ -95,7 +95,7 @@ func (e *Position) UnmarshalText(text []byte) error {
switch s := strings.ToLower(string(text)); s {
default:
*e = PositionNone
- for _, p := range strings.Split(s, ",") {
+ for p := range strings.SplitSeq(s, ",") {
switch p {
case "left":
*e |= PositionLeft
diff --git a/cmdtest/environment_test.go b/cmdtest/environment_test.go
index 86ab0b4de..9e4f660d2 100644
--- a/cmdtest/environment_test.go
+++ b/cmdtest/environment_test.go
@@ -351,7 +351,7 @@ func TestEnvironmentVariables(t *testing.T) {
parseFileFilters := func(out string) (extensions []string) {
// Match: - (^|/)[^/]*\.jpg$
find := regexp.MustCompile(`^- \(\^\|\/\)\[\^\/\]\*\\\.(.*?)\$$`)
- for _, line := range strings.Split(out, "\n") {
+ for line := range strings.SplitSeq(out, "\n") {
if m := find.FindStringSubmatch(line); m != nil {
extensions = append(extensions, m[1])
}
diff --git a/fs/config/flags/flags.go b/fs/config/flags/flags.go
index 953a3d0fd..912c0b2d6 100644
--- a/fs/config/flags/flags.go
+++ b/fs/config/flags/flags.go
@@ -70,7 +70,7 @@ func (gs *Groups) Include(groupsString string) *Groups {
return gs
}
want := map[string]bool{}
- for _, groupName := range strings.Split(groupsString, ",") {
+ for groupName := range strings.SplitSeq(groupsString, ",") {
_, ok := All.ByName[groupName]
if !ok {
fs.Fatalf(nil, "Couldn't find group %q in command annotation", groupName)
@@ -173,7 +173,7 @@ func installFlag(flags *pflag.FlagSet, name string, groupsString string) {
// Add flag to Group if it is a global flag
if groupsString != "" && flags == pflag.CommandLine {
- for _, groupName := range strings.Split(groupsString, ",") {
+ for groupName := range strings.SplitSeq(groupsString, ",") {
if groupName == "rc-" {
groupName = "RC"
}
diff --git a/fs/mimetype.go b/fs/mimetype.go
index 93f82172d..44d423738 100644
--- a/fs/mimetype.go
+++ b/fs/mimetype.go
@@ -32,7 +32,7 @@ func init() {
{"video/x-matroska", ".mpv,.mkv"},
{"application/x-subrip", ".srt"},
} {
- for _, ext := range strings.Split(t.extensions, ",") {
+ for ext := range strings.SplitSeq(t.extensions, ",") {
if mime.TypeByExtension(ext) == "" {
err := mime.AddExtensionType(ext, t.mimeType)
if err != nil {
diff --git a/fs/rc/config.go b/fs/rc/config.go
index 2fb0fc424..7aa0c9fed 100644
--- a/fs/rc/config.go
+++ b/fs/rc/config.go
@@ -64,7 +64,7 @@ func filterBlocks(in Params, f func(oi fs.OptionsInfo)) (err error) {
return err
}
blocks := map[string]struct{}{}
- for _, name := range strings.Split(blocksStr, ",") {
+ for name := range strings.SplitSeq(blocksStr, ",") {
if name != "" {
blocks[name] = struct{}{}
}
diff --git a/fs/sync/sync.go b/fs/sync/sync.go
index e5feb5e3c..a425345a4 100644
--- a/fs/sync/sync.go
+++ b/fs/sync/sync.go
@@ -743,7 +743,7 @@ func parseTrackRenamesStrategy(strategies string) (strategy trackRenamesStrategy
if len(strategies) == 0 {
return strategy, nil
}
- for _, s := range strings.Split(strategies, ",") {
+ for s := range strings.SplitSeq(strategies, ",") {
switch s {
case "hash":
strategy |= trackRenamesStrategyHash
diff --git a/fstest/runs/run.go b/fstest/runs/run.go
index 2859e7392..c898d3919 100644
--- a/fstest/runs/run.go
+++ b/fstest/runs/run.go
@@ -157,7 +157,7 @@ func testsToRegexp(tests []string) string {
// Make a trie showing which parts are used at each level
for _, test := range tests {
parent := split
- for _, name := range strings.Split(test, "/") {
+ for name := range strings.SplitSeq(test, "/") {
current := parent[name]
if current == nil {
current = trie{}
diff --git a/fstest/testserver/testserver.go b/fstest/testserver/testserver.go
index 2d7fe44bd..892eecd3b 100644
--- a/fstest/testserver/testserver.go
+++ b/fstest/testserver/testserver.go
@@ -82,7 +82,7 @@ func start(name string) error {
// parse the output and set environment vars from it
var connect string
var connectDelay time.Duration
- for _, line := range bytes.Split(out, []byte("\n")) {
+ for line := range bytes.SplitSeq(out, []byte("\n")) {
line = bytes.TrimSpace(line)
part := matchLine.FindSubmatch(line)
if part != nil {
diff --git a/lib/encoder/encoder.go b/lib/encoder/encoder.go
index c8f41d76c..faefdfb3c 100644
--- a/lib/encoder/encoder.go
+++ b/lib/encoder/encoder.go
@@ -184,8 +184,8 @@ func (mask MultiEncoder) String() string {
// Set converts a string into a MultiEncoder
func (mask *MultiEncoder) Set(in string) error {
var out MultiEncoder
- parts := strings.Split(in, ",")
- for _, part := range parts {
+ parts := strings.SplitSeq(in, ",")
+ for part := range parts {
part = strings.TrimSpace(part)
if bits, ok := nameToEncoding[part]; ok {
out |= bits
diff --git a/vfs/vfstest/fs.go b/vfs/vfstest/fs.go
index c9db4fa19..0391f855c 100644
--- a/vfs/vfstest/fs.go
+++ b/vfs/vfstest/fs.go
@@ -212,7 +212,7 @@ type dirMap map[string]struct{}
// Create a dirMap from a string
func newDirMap(dirString string) (dm dirMap) {
dm = make(dirMap)
- for _, entry := range strings.Split(dirString, "|") {
+ for entry := range strings.SplitSeq(dirString, "|") {
if entry != "" {
dm[entry] = struct{}{}
}