From 67ba75f2f72c198aca62ca44a6399bf78cc75a31 Mon Sep 17 00:00:00 2001 From: zhijian Date: Wed, 31 Jan 2024 16:18:12 +0800 Subject: [PATCH] cmd/sync: fix the dst password is not removed (#4390) --- cmd/main.go | 18 +++++++++++------- cmd/sync.go | 3 +-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 74d795995ce4..daa11d798c8a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -344,15 +344,19 @@ func setup(c *cli.Context, n int) { } } -func removePassword(uri string) { +func removePassword(uris ...string) { args := make([]string, len(os.Args)) copy(args, os.Args) - uri2 := utils.RemovePassword(uri) - if uri2 != uri { - for i, a := range os.Args { - if a == uri { - args[i] = uri2 - break + var idx int + for _, uri := range uris { + uri2 := utils.RemovePassword(uri) + if uri2 != uri { + for i := idx; i < len(os.Args); i++ { + if os.Args[i] == uri { + args[i] = uri2 + idx = i + 1 + break + } } } } diff --git a/cmd/sync.go b/cmd/sync.go index 6ee7794f75f2..1b1aab24bc66 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -411,8 +411,7 @@ func doSync(c *cli.Context) error { // Windows support `\` and `/` as its separator, Unix only use `/` srcURL := c.Args().Get(0) dstURL := c.Args().Get(1) - removePassword(srcURL) - removePassword(dstURL) + removePassword(srcURL, dstURL) if runtime.GOOS == "windows" { if !strings.Contains(srcURL, "://") { srcURL = strings.Replace(srcURL, "\\", "/", -1)