github-vet / github-vet/rangeloop-pointer-findings

l3uddz/crop: cmd/upload.go; 118 LoC

Open
#9,926 0 comments 0 reactions 0 assignees View on GitHub
fresh large
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [l3uddz/crop](https://www.github.com/l3uddz/crop) at [cmd/upload.go](https://github.com/l3uddz/crop/blob/9c9802832ef5db0964570caf2c194790379583df/cmd/upload.go#L36-L153)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to uploaderConfig was used in a composite literal at line 52

[Click here to see the code in its original context.](https://github.com/l3uddz/crop/blob/9c9802832ef5db0964570caf2c194790379583df/cmd/upload.go#L36-L153)

Click here to show the 118 line(s) of Go which triggered the analyzer.

```go
for _, uploaderConfig := range config.Config.Uploader {
log := log.WithField("uploader", uploaderConfig.Name)

// skip disabled uploader(s)
if !uploaderConfig.Enabled {
log.Debug("Skipping disabled uploader")
continue
}

// skip uploader specific chosen
if flagUploader != "" && !strings.EqualFold(uploaderConfig.Name, flagUploader) {
log.Debugf("Skipping uploader as not: %q", flagUploader)
continue
}

// create uploader
upload, err := uploader.New(config.Config, &uploaderConfig, uploaderConfig.Name)
if err != nil {
log.WithError(err).Error("Failed initializing uploader, skipping...")
continue
}

serviceAccountCount := upload.RemoteServiceAccountFiles.ServiceAccountsCount()
if serviceAccountCount > 0 {
upload.Log.WithField("found_files", serviceAccountCount).Info("Loaded service accounts")
} else {
// no service accounts were loaded
// check to see if any of the copy or move remote(s) are banned
banned, expiry := rclone.AnyRemotesBanned(upload.Config.Remotes.Copy)
if banned && !expiry.IsZero() {
// one of the copy remotes is banned, abort
upload.Log.WithFields(logrus.Fields{
"expires_time": expiry,
"expires_in": humanize.Time(expiry),
}).Warn("Cannot proceed with upload as a copy remote is banned")
continue
}

banned, expiry = rclone.AnyRemotesBanned([]string{upload.Config.Remotes.Move})
if banned && !expiry.IsZero() {
// the move remote is banned, abort
upload.Log.WithFields(logrus.Fields{
"expires_time": expiry,
"expires_in": humanize.Time(expiry),
}).Warn("Cannot proceed with upload as the move remote is banned")
continue
}
}

log.Info("Uploader commencing...")

// refresh details about files to upload
if err := upload.RefreshLocalFiles(); err != nil {
upload.Log.WithError(err).Error("Failed refreshing details of files to upload")
continue
}

if len(upload.LocalFiles) == 0 {
// there are no files to upload
upload.Log.Info("There were no files found, skipping...")
continue
}

// check if upload criteria met
forced := false

if !flagNoCheck {
// no check was not enabled
res, err := upload.Check()
if err != nil {
upload.Log.WithError(err).Error("Failed checking if uploader check conditions met, skipping...")
continue
}

if !res.Passed {
// get free disk space
freeDiskSpace := "Unknown"
du, err := disk.Usage(upload.Config.LocalFolder)
if err == nil {
freeDiskSpace = humanize.IBytes(du.Free)
}

// check available disk space
switch {
case err != nil && upload.Config.Check.MinFreeSpace > 0:
// error checking free space
upload.Log.WithError(err).Errorf("Failed checking available free space for: %q",
upload.Config.LocalFolder)
case err == nil && du.Free < upload.Config.Check.MinFreeSpace:
// free space has gone below the free space threshold
forced = true
upload.Log.WithFields(logrus.Fields{
"until": res.Info,
"free_disk": freeDiskSpace,
}).Infof("Upload conditions not met, however, proceeding as free space below %s",
humanize.IBytes(upload.Config.Check.MinFreeSpace))
default:
break
}

if !forced {
upload.Log.WithFields(logrus.Fields{
"until": res.Info,
"free_disk": freeDiskSpace,
}).Info("Upload conditions not met, skipping...")
continue
}

// the upload was forced as min_free_size was met
}
}

// perform upload
if err := performUpload(upload, forced); err != nil {
upload.Log.WithError(err).Error("Error occurred while running uploader, skipping...")
continue
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 9c9802832ef5db0964570caf2c194790379583df

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.