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: fix gocritic lint issue elseif

albertonye82b5b11af74
diff --git a/backend/azurefiles/azurefiles.go b/backend/azurefiles/azurefiles.go
index 06046f060..0cae6620f 100644
--- a/backend/azurefiles/azurefiles.go
+++ b/backend/azurefiles/azurefiles.go
@@ -1035,12 +1035,10 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
if _, createErr := fc.Create(ctx, size, nil); createErr != nil {
return fmt.Errorf("update: unable to create file: %w", createErr)
}
- } else {
+ } else if size != o.Size() {
// Resize the file if needed
- if size != o.Size() {
- if _, resizeErr := fc.Resize(ctx, size, nil); resizeErr != nil {
- return fmt.Errorf("update: unable to resize while trying to update: %w ", resizeErr)
- }
+ if _, resizeErr := fc.Resize(ctx, size, nil); resizeErr != nil {
+ return fmt.Errorf("update: unable to resize while trying to update: %w ", resizeErr)
}
}
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index 7ca097354..cb4e0e62b 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -409,18 +409,16 @@ func NewFs(ctx context.Context, name, rootPath string, m configmap.Mapper) (fs.F
if err != nil {
return nil, fmt.Errorf("failed to connect to the Plex API %v: %w", opt.PlexURL, err)
}
- } else {
- if opt.PlexPassword != "" && opt.PlexUsername != "" {
- decPass, err := obscure.Reveal(opt.PlexPassword)
- if err != nil {
- decPass = opt.PlexPassword
- }
- f.plexConnector, err = newPlexConnector(f, opt.PlexURL, opt.PlexUsername, decPass, opt.PlexInsecure, func(token string) {
- m.Set("plex_token", token)
- })
- if err != nil {
- return nil, fmt.Errorf("failed to connect to the Plex API %v: %w", opt.PlexURL, err)
- }
+ } else if opt.PlexPassword != "" && opt.PlexUsername != "" {
+ decPass, err := obscure.Reveal(opt.PlexPassword)
+ if err != nil {
+ decPass = opt.PlexPassword
+ }
+ f.plexConnector, err = newPlexConnector(f, opt.PlexURL, opt.PlexUsername, decPass, opt.PlexInsecure, func(token string) {
+ m.Set("plex_token", token)
+ })
+ if err != nil {
+ return nil, fmt.Errorf("failed to connect to the Plex API %v: %w", opt.PlexURL, err)
}
}
}
diff --git a/backend/cache/handle.go b/backend/cache/handle.go
index 687e96cec..11772eb6e 100644
--- a/backend/cache/handle.go
+++ b/backend/cache/handle.go
@@ -415,10 +415,8 @@ func (w *worker) run() {
continue
}
}
- } else {
- if w.r.storage().HasChunk(w.r.cachedObject, chunkStart) {
- continue
- }
+ } else if w.r.storage().HasChunk(w.r.cachedObject, chunkStart) {
+ continue
}
chunkEnd := chunkStart + int64(w.r.cacheFs().opt.ChunkSize)
diff --git a/backend/oracleobjectstorage/byok.go b/backend/oracleobjectstorage/byok.go
index 85daa158d..b3392515b 100644
--- a/backend/oracleobjectstorage/byok.go
+++ b/backend/oracleobjectstorage/byok.go
@@ -58,12 +58,10 @@ func populateSSECustomerKeys(opt *Options) error {
sha256Checksum := base64.StdEncoding.EncodeToString(getSha256(decoded))
if opt.SSECustomerKeySha256 == "" {
opt.SSECustomerKeySha256 = sha256Checksum
- } else {
- if opt.SSECustomerKeySha256 != sha256Checksum {
- return fmt.Errorf("the computed SHA256 checksum "+
- "(%v) of the key doesn't match the config entry sse_customer_key_sha256=(%v)",
- sha256Checksum, opt.SSECustomerKeySha256)
- }
+ } else if opt.SSECustomerKeySha256 != sha256Checksum {
+ return fmt.Errorf("the computed SHA256 checksum "+
+ "(%v) of the key doesn't match the config entry sse_customer_key_sha256=(%v)",
+ sha256Checksum, opt.SSECustomerKeySha256)
}
if opt.SSECustomerAlgorithm == "" {
opt.SSECustomerAlgorithm = sseDefaultAlgorithm
diff --git a/backend/s3/s3.go b/backend/s3/s3.go
index 46426e77e..fbc3327a0 100644
--- a/backend/s3/s3.go
+++ b/backend/s3/s3.go
@@ -4173,11 +4173,9 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error {
if opt.noSkipMarkers {
// process directory markers as files
isDirectory = false
- } else {
+ } else if remote == f.opt.Enc.ToStandardPath(opt.directory) {
// Don't insert the root directory
- if remote == f.opt.Enc.ToStandardPath(opt.directory) {
- continue
- }
+ continue
}
}
remote = remote[len(opt.prefix):]
diff --git a/backend/yandex/yandex.go b/backend/yandex/yandex.go
index 806c5f915..798cccd6c 100644
--- a/backend/yandex/yandex.go
+++ b/backend/yandex/yandex.go
@@ -296,16 +296,14 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
//request object meta info
if info, err := f.readMetaDataForPath(ctx, f.diskRoot, &api.ResourceInfoRequestOptions{}); err != nil {
- } else {
- if info.ResourceType == "file" {
- rootDir := path.Dir(root)
- if rootDir == "." {
- rootDir = ""
- }
- f.setRoot(rootDir)
- // return an error with an fs which points to the parent
- return f, fs.ErrorIsFile
+ } else if info.ResourceType == "file" {
+ rootDir := path.Dir(root)
+ if rootDir == "." {
+ rootDir = ""
}
+ f.setRoot(rootDir)
+ // return an error with an fs which points to the parent
+ return f, fs.ErrorIsFile
}
return f, nil
}
diff --git a/cmd/bisync/deltas.go b/cmd/bisync/deltas.go
index 167bd70fd..1cb783d56 100644
--- a/cmd/bisync/deltas.go
+++ b/cmd/bisync/deltas.go
@@ -190,51 +190,49 @@ func (b *bisyncRun) findDeltas(fctx context.Context, f fs.Fs, oldListing string,
b.indent(msg, file, Color(terminal.RedFg, "File was deleted"))
ds.deleted++
d |= deltaDeleted
- } else {
+ } else if !now.isDir(file) {
// skip dirs here, as we only care if they are new/deleted, not newer/older
- if !now.isDir(file) {
- whatchanged := []string{}
- if b.opt.Compare.Size {
- if sizeDiffers(old.getSize(file), now.getSize(file)) {
- fs.Debugf(file, "(old: %v current: %v)", old.getSize(file), now.getSize(file))
- if now.getSize(file) > old.getSize(file) {
- whatchanged = append(whatchanged, Color(terminal.MagentaFg, "size (larger)"))
- d |= deltaLarger
- } else {
- whatchanged = append(whatchanged, Color(terminal.MagentaFg, "size (smaller)"))
- d |= deltaSmaller
- }
- s = now.getSize(file)
- }
- }
- if b.opt.Compare.Modtime {
- if timeDiffers(fctx, old.getTime(file), now.getTime(file), f, f) {
- if old.beforeOther(now, file) {
- fs.Debugf(file, "(old: %v current: %v)", old.getTime(file), now.getTime(file))
- whatchanged = append(whatchanged, Color(terminal.MagentaFg, "time (newer)"))
- d |= deltaNewer
- } else { // Current version is older than prior sync.
- fs.Debugf(file, "(old: %v current: %v)", old.getTime(file), now.getTime(file))
- whatchanged = append(whatchanged, Color(terminal.MagentaFg, "time (older)"))
- d |= deltaOlder
- }
- t = now.getTime(file)
+ whatchanged := []string{}
+ if b.opt.Compare.Size {
+ if sizeDiffers(old.getSize(file), now.getSize(file)) {
+ fs.Debugf(file, "(old: %v current: %v)", old.getSize(file), now.getSize(file))
+ if now.getSize(file) > old.getSize(file) {
+ whatchanged = append(whatchanged, Color(terminal.MagentaFg, "size (larger)"))
+ d |= deltaLarger
+ } else {
+ whatchanged = append(whatchanged, Color(terminal.MagentaFg, "size (smaller)"))
+ d |= deltaSmaller
}
+ s = now.getSize(file)
}
- if b.opt.Compare.Checksum {
- if hashDiffers(old.getHash(file), now.getHash(file), old.hash, now.hash, old.getSize(file), now.getSize(file)) {
- fs.Debugf(file, "(old: %v current: %v)", old.getHash(file), now.getHash(file))
- whatchanged = append(whatchanged, Color(terminal.MagentaFg, "hash"))
- d |= deltaHash
- h = now.getHash(file)
+ }
+ if b.opt.Compare.Modtime {
+ if timeDiffers(fctx, old.getTime(file), now.getTime(file), f, f) {
+ if old.beforeOther(now, file) {
+ fs.Debugf(file, "(old: %v current: %v)", old.getTime(file), now.getTime(file))
+ whatchanged = append(whatchanged, Color(terminal.MagentaFg, "time (newer)"))
+ d |= deltaNewer
+ } else { // Current version is older than prior sync.
+ fs.Debugf(file, "(old: %v current: %v)", old.getTime(file), now.getTime(file))
+ whatchanged = append(whatchanged, Color(terminal.MagentaFg, "time (older)"))
+ d |= deltaOlder
}
+ t = now.getTime(file)
}
- // concat changes and print log
- if d.is(deltaModified) {
- summary := fmt.Sprintf(Color(terminal.YellowFg, "File changed: %s"), strings.Join(whatchanged, ", "))
- b.indent(msg, file, summary)
+ }
+ if b.opt.Compare.Checksum {
+ if hashDiffers(old.getHash(file), now.getHash(file), old.hash, now.hash, old.getSize(file), now.getSize(file)) {
+ fs.Debugf(file, "(old: %v current: %v)", old.getHash(file), now.getHash(file))
+ whatchanged = append(whatchanged, Color(terminal.MagentaFg, "hash"))
+ d |= deltaHash
+ h = now.getHash(file)
}
}
+ // concat changes and print log
+ if d.is(deltaModified) {
+ summary := fmt.Sprintf(Color(terminal.YellowFg, "File changed: %s"), strings.Join(whatchanged, ", "))
+ b.indent(msg, file, summary)
+ }
}
if d.is(deltaModified) {
diff --git a/cmd/bisync/operations.go b/cmd/bisync/operations.go
index a1787edaa..b457645fa 100644
--- a/cmd/bisync/operations.go
+++ b/cmd/bisync/operations.go
@@ -476,10 +476,8 @@ func (b *bisyncRun) checkSync(listing1, listing2 string) error {
if !files2.has(file) && !files2.has(b.aliases.Alias(file)) {
b.indent("ERROR", file, "Path1 file not found in Path2")
ok = false
- } else {
- if !b.fileInfoEqual(file, files2.getTryAlias(file, b.aliases.Alias(file)), files1, files2) {
- ok = false
- }
+ } else if !b.fileInfoEqual(file, files2.getTryAlias(file, b.aliases.Alias(file)), files1, files2) {
+ ok = false
}
}
for _, file := range files2.list {
diff --git a/fs/config/crypt.go b/fs/config/crypt.go
index c1de69e7c..8fc476f82 100644
--- a/fs/config/crypt.go
+++ b/fs/config/crypt.go
@@ -153,16 +153,14 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
}
configKey = []byte(obscure.MustReveal(string(obscuredKey)))
fs.Debugf(nil, "using _RCLONE_CONFIG_KEY_FILE for configKey")
- } else {
- if len(configKey) == 0 {
- if usingPasswordCommand {
- return nil, errors.New("using --password-command derived password, unable to decrypt configuration")
- }
- if !ci.AskPassword {
- return nil, errors.New("unable to decrypt configuration and not allowed to ask for password - set RCLONE_CONFIG_PASS to your configuration password")
- }
- getConfigPassword("Enter configuration password:")
+ } else if len(configKey) == 0 {
+ if usingPasswordCommand {
+ return nil, errors.New("using --password-command derived password, unable to decrypt configuration")
+ }
+ if !ci.AskPassword {
+ return nil, errors.New("unable to decrypt configuration and not allowed to ask for password - set RCLONE_CONFIG_PASS to your configuration password")
}
+ getConfigPassword("Enter configuration password:")
}
// Nonce is first 24 bytes of the ciphertext
diff --git a/fs/operations/operations.go b/fs/operations/operations.go
index 2a25bbc23..adeba8d59 100644
--- a/fs/operations/operations.go
+++ b/fs/operations/operations.go
@@ -1865,14 +1865,12 @@ func BackupDir(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, srcFileName string)
if OverlappingFilterCheck(ctx, backupDir, fsrc) {
return nil, fserrors.FatalError(errors.New("source and parameter to --backup-dir mustn't overlap"))
}
- } else {
- if ci.Suffix == "" {
- if SameDir(fdst, backupDir) {
- return nil, fserrors.FatalError(errors.New("destination and parameter to --backup-dir mustn't be the same"))
- }
- if SameDir(fsrc, backupDir) {
- return nil, fserrors.FatalError(errors.New("source and parameter to --backup-dir mustn't be the same"))
- }
+ } else if ci.Suffix == "" {
+ if SameDir(fdst, backupDir) {
+ return nil, fserrors.FatalError(errors.New("destination and parameter to --backup-dir mustn't be the same"))
+ }
+ if SameDir(fsrc, backupDir) {
+ return nil, fserrors.FatalError(errors.New("source and parameter to --backup-dir mustn't be the same"))
}
}
} else if ci.Suffix != "" {
@@ -2041,15 +2039,13 @@ func moveOrCopyFile(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, dstFileName str
}
_, err = Op(ctx, fdst, dstObj, dstFileName, srcObj)
- } else {
- if !cp {
- if ci.IgnoreExisting {
- fs.Debugf(srcObj, "Not removing source file as destination file exists and --ignore-existing is set")
- logger(ctx, Match, srcObj, dstObj, nil)
- } else if !SameObject(srcObj, dstObj) {
- err = DeleteFile(ctx, srcObj)
- logger(ctx, Differ, srcObj, dstObj, nil)
- }
+ } else if !cp {
+ if ci.IgnoreExisting {
+ fs.Debugf(srcObj, "Not removing source file as destination file exists and --ignore-existing is set")
+ logger(ctx, Match, srcObj, dstObj, nil)
+ } else if !SameObject(srcObj, dstObj) {
+ err = DeleteFile(ctx, srcObj)
+ logger(ctx, Differ, srcObj, dstObj, nil)
}
}
return err
diff --git a/fs/operations/rc.go b/fs/operations/rc.go
index 4b01108d2..46bf41770 100644
--- a/fs/operations/rc.go
+++ b/fs/operations/rc.go
@@ -819,10 +819,8 @@ func rcCheck(ctx context.Context, in rc.Params) (out rc.Params, err error) {
if srcFs != nil {
return nil, rc.NewErrParamInvalid(errors.New("only supply dstFs when using checkFileHash"))
}
- } else {
- if srcFs == nil {
- return nil, rc.NewErrParamInvalid(errors.New("need srcFs parameter when not using checkFileHash"))
- }
+ } else if srcFs == nil {
+ return nil, rc.NewErrParamInvalid(errors.New("need srcFs parameter when not using checkFileHash"))
}
oneway, _ := in.GetBool("oneway")
diff --git a/lib/dircache/dircache.go b/lib/dircache/dircache.go
index 8cab02453..7fdf9e1af 100644
--- a/lib/dircache/dircache.go
+++ b/lib/dircache/dircache.go
@@ -358,10 +358,8 @@ func (dc *DirCache) RootParentID(ctx context.Context, create bool) (ID string, e
return "", err
}
dc.rootParentID = rootParentID
- } else {
- if dc.rootID == dc.trueRootID {
- return "", errors.New("is root directory")
- }
+ } else if dc.rootID == dc.trueRootID {
+ return "", errors.New("is root directory")
}
if dc.rootParentID == "" {
return "", errors.New("internal error: didn't find rootParentID")
diff --git a/vfs/write.go b/vfs/write.go
index c1dfdf414..c799f98d5 100644
--- a/vfs/write.go
+++ b/vfs/write.go
@@ -203,11 +203,9 @@ func (fh *WriteFileHandle) close() (err error) {
if err == nil {
fh.file.setObject(fh.o)
err = writeCloseErr
- } else {
+ } else if fh.file.getObject() == nil {
// Remove vfs file entry when no object is present
- if fh.file.getObject() == nil {
- _ = fh.file.Remove()
- }
+ _ = fh.file.Remove()
}
return err
}