From acea32d0b1b8f40f42eaaab26ce9096385cc53fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Tue, 9 Apr 2019 00:16:31 +0200 Subject: [PATCH] fixed variable shadowing warnings --- internal/pkg/category/category.go | 6 ++++-- internal/pkg/images/synchronizeLocalFiles.go | 7 ++++--- internal/pkg/images/synchronizePiwigo.go | 3 ++- internal/pkg/localFileStructure/checksumCalculator.go | 2 +- internal/pkg/piwigo/serverContext.go | 5 +++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/pkg/category/category.go b/internal/pkg/category/category.go index ce46cda..5ae50d2 100644 --- a/internal/pkg/category/category.go +++ b/internal/pkg/category/category.go @@ -78,7 +78,8 @@ func updatePiwigoCategoriesFromServer(piwigoApi piwigo.CategoryApi, db datastore } for _, pwgCat := range categories { - dbCat, err := db.GetCategoryByPiwigoId(pwgCat.Id) + var dbCat datastore.CategoryData + dbCat, err = db.GetCategoryByPiwigoId(pwgCat.Id) if err == datastore.ErrorRecordNotFound { logrus.Debugf("Adding category %s", pwgCat.Key) dbCat = datastore.CategoryData{ @@ -125,7 +126,8 @@ func createMissingCategories(piwigoApi piwigo.CategoryApi, db datastore.Category for _, category := range missingCategories { logrus.Infof("Creating category %s", category.Key) - parentId, err := getParentId(category, db) + var parentId int + parentId, err = getParentId(category, db) if err != nil { return err } diff --git a/internal/pkg/images/synchronizeLocalFiles.go b/internal/pkg/images/synchronizeLocalFiles.go index 8d1276a..17dce3c 100644 --- a/internal/pkg/images/synchronizeLocalFiles.go +++ b/internal/pkg/images/synchronizeLocalFiles.go @@ -83,7 +83,8 @@ func checkFileForChangesWorker(workQueue <-chan localFileStructure.FilesystemNod metadata.FullImagePath = file.Path metadata.CategoryPath = filepath.Dir(file.Key) - category, err := categoryDb.GetCategoryByKey(metadata.CategoryPath) + var category datastore.CategoryData + category, err = categoryDb.GetCategoryByKey(metadata.CategoryPath) if err == nil { metadata.CategoryPiwigoId = category.PiwigoId } else { @@ -127,10 +128,10 @@ func synchronizeLocalImageMetadataFindFilesToDelete(imageDb datastore.ImageMetad } for _, img := range images { - if _, err := os.Stat(img.FullImagePath); os.IsNotExist(err) { + if _, err = os.Stat(img.FullImagePath); os.IsNotExist(err) { img.UploadRequired = false img.DeleteRequired = true - err := imageDb.SaveImageMetadata(img) + err = imageDb.SaveImageMetadata(img) if err != nil { return err } diff --git a/internal/pkg/images/synchronizePiwigo.go b/internal/pkg/images/synchronizePiwigo.go index 03229aa..ed26b7d 100644 --- a/internal/pkg/images/synchronizePiwigo.go +++ b/internal/pkg/images/synchronizePiwigo.go @@ -98,7 +98,8 @@ func checkPiwigoForChangedImages(provider datastore.ImageMetadataProvider, piwig if img.PiwigoId == 0 { continue } - state, err := piwigoCtx.ImageCheckFile(img.PiwigoId, img.Md5Sum) + var state int + state, err = piwigoCtx.ImageCheckFile(img.PiwigoId, img.Md5Sum) if err != nil { logrus.Warnf("Error during file change check of file %s", img.FullImagePath) continue diff --git a/internal/pkg/localFileStructure/checksumCalculator.go b/internal/pkg/localFileStructure/checksumCalculator.go index e97613d..0f4450a 100644 --- a/internal/pkg/localFileStructure/checksumCalculator.go +++ b/internal/pkg/localFileStructure/checksumCalculator.go @@ -22,7 +22,7 @@ func CalculateFileCheckSums(filePath string) (string, error) { defer file.Close() hash := md5.New() - if _, err := io.Copy(hash, file); err != nil { + if _, err = io.Copy(hash, file); err != nil { logrus.Errorf("Could calculate md5 sum of file %s", filePath) return "", err } diff --git a/internal/pkg/piwigo/serverContext.go b/internal/pkg/piwigo/serverContext.go index 6d8b3fb..d294ab5 100644 --- a/internal/pkg/piwigo/serverContext.go +++ b/internal/pkg/piwigo/serverContext.go @@ -217,7 +217,8 @@ func (context *ServerContext) imagesExistOnPiwigoBatch(md5sums []string, existRe logrus.Tracef("Missing file with md5sum: %s", key) existResults[key] = 0 } else { - piwigoId, err := strconv.Atoi(value) + var piwigoId int + piwigoId, err = strconv.Atoi(value) if err != nil { logrus.Warnf("could not parse piwigoid of file %s", key) continue @@ -328,7 +329,7 @@ func (context *ServerContext) executePiwigoRequest(formData url.Values, decodedR } defer response.Body.Close() - if err := json.NewDecoder(response.Body).Decode(decodedResponse); err != nil { + if err = json.NewDecoder(response.Body).Decode(decodedResponse); err != nil { logrus.Errorln(err) return err }