build: fix gocritic lint issue elseif

This commit is contained in:
albertony 2024-05-31 15:18:56 +02:00 committed by Nick Craig-Wood
parent 4454ed9d3b
commit e82b5b11af
13 changed files with 92 additions and 120 deletions

View file

@ -1035,14 +1035,12 @@ 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)
}
}
}
// Measure the size if it is unknown
if sizeUnknown {

View file

@ -409,8 +409,7 @@ 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 != "" {
} else if opt.PlexPassword != "" && opt.PlexUsername != "" {
decPass, err := obscure.Reveal(opt.PlexPassword)
if err != nil {
decPass = opt.PlexPassword
@ -423,7 +422,6 @@ func NewFs(ctx context.Context, name, rootPath string, m configmap.Mapper) (fs.F
}
}
}
}
dbPath := f.opt.DbPath
chunkPath := f.opt.ChunkPath

View file

@ -415,11 +415,9 @@ func (w *worker) run() {
continue
}
}
} else {
if w.r.storage().HasChunk(w.r.cachedObject, chunkStart) {
} else if w.r.storage().HasChunk(w.r.cachedObject, chunkStart) {
continue
}
}
chunkEnd := chunkStart + int64(w.r.cacheFs().opt.ChunkSize)
// TODO: Remove this comment if it proves to be reliable for #1896

View file

@ -58,13 +58,11 @@ func populateSSECustomerKeys(opt *Options) error {
sha256Checksum := base64.StdEncoding.EncodeToString(getSha256(decoded))
if opt.SSECustomerKeySha256 == "" {
opt.SSECustomerKeySha256 = sha256Checksum
} else {
if 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)
}
}
if opt.SSECustomerAlgorithm == "" {
opt.SSECustomerAlgorithm = sseDefaultAlgorithm
}

View file

@ -4173,13 +4173,11 @@ 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
}
}
}
remote = remote[len(opt.prefix):]
if isDirectory {
// process directory markers as directories

View file

@ -296,8 +296,7 @@ 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" {
} else if info.ResourceType == "file" {
rootDir := path.Dir(root)
if rootDir == "." {
rootDir = ""
@ -306,7 +305,6 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
// return an error with an fs which points to the parent
return f, fs.ErrorIsFile
}
}
return f, nil
}

View file

@ -190,9 +190,8 @@ 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)) {
@ -235,7 +234,6 @@ func (b *bisyncRun) findDeltas(fctx context.Context, f fs.Fs, oldListing string,
b.indent(msg, file, summary)
}
}
}
if d.is(deltaModified) {
ds.deltas[file] = d

View file

@ -476,12 +476,10 @@ 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) {
} else if !b.fileInfoEqual(file, files2.getTryAlias(file, b.aliases.Alias(file)), files1, files2) {
ok = false
}
}
}
for _, file := range files2.list {
if !files1.has(file) && !files1.has(b.aliases.Alias(file)) {
b.indent("ERROR", file, "Path2 file not found in Path1")

View file

@ -153,8 +153,7 @@ 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 {
} else if len(configKey) == 0 {
if usingPasswordCommand {
return nil, errors.New("using --password-command derived password, unable to decrypt configuration")
}
@ -163,7 +162,6 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
}
getConfigPassword("Enter configuration password:")
}
}
// Nonce is first 24 bytes of the ciphertext
var nonce [24]byte

View file

@ -1865,8 +1865,7 @@ 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 == "" {
} 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"))
}
@ -1874,7 +1873,6 @@ func BackupDir(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, srcFileName string)
return nil, fserrors.FatalError(errors.New("source and parameter to --backup-dir mustn't be the same"))
}
}
}
} else if ci.Suffix != "" {
// --backup-dir is not set but --suffix is - use the destination as the backupDir
backupDir = fdst
@ -2041,8 +2039,7 @@ func moveOrCopyFile(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, dstFileName str
}
_, err = Op(ctx, fdst, dstObj, dstFileName, srcObj)
} else {
if !cp {
} 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)
@ -2051,7 +2048,6 @@ func moveOrCopyFile(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, dstFileName str
logger(ctx, Differ, srcObj, dstObj, nil)
}
}
}
return err
}

View file

@ -819,11 +819,9 @@ 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 {
} else if srcFs == nil {
return nil, rc.NewErrParamInvalid(errors.New("need srcFs parameter when not using checkFileHash"))
}
}
oneway, _ := in.GetBool("oneway")
download, _ := in.GetBool("download")

View file

@ -358,11 +358,9 @@ func (dc *DirCache) RootParentID(ctx context.Context, create bool) (ID string, e
return "", err
}
dc.rootParentID = rootParentID
} else {
if dc.rootID == dc.trueRootID {
} else if dc.rootID == dc.trueRootID {
return "", errors.New("is root directory")
}
}
if dc.rootParentID == "" {
return "", errors.New("internal error: didn't find rootParentID")
}

View file

@ -203,12 +203,10 @@ 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()
}
}
return err
}