From af4ea7c7d5fbc5bfd012ec84a892fbc96e2b8e85 Mon Sep 17 00:00:00 2001 From: Shubham Hibare Date: Sun, 2 Apr 2023 12:52:06 +0530 Subject: [PATCH 1/2] Fix version check --- internal/version/version.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/version/version.go b/internal/version/version.go index 2c26bd2..fea250f 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "github.com/hibare/GoS3Backup/internal/constants" log "github.com/sirupsen/logrus" @@ -47,7 +48,7 @@ func CheckLatestRelease() { return } - LatestVersion = release.TagName + LatestVersion = strings.TrimPrefix(release.TagName, "v") status, _ := IsNewVersionAvailable() log.Infof("Version update available: %v, Current version: %s, Latest Version: %s", status, CurrentVersion, LatestVersion) From c153ef41ba89e48ccc1f96855fecec9a7868bed0 Mon Sep 17 00:00:00 2001 From: Shubham Hibare Date: Sun, 2 Apr 2023 13:17:07 +0530 Subject: [PATCH 2/2] fix nil pointer exception --- internal/s3/s3.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/s3/s3.go b/internal/s3/s3.go index 52cc28e..b46599a 100644 --- a/internal/s3/s3.go +++ b/internal/s3/s3.go @@ -40,25 +40,25 @@ func Upload(sess *session.Session, bucket, prefix, baseDir string) (int, int, in totalDirs = len(dirs) for _, file := range files { - file, err := os.Open(file) + fp, err := os.Open(file) if err != nil { - log.Errorf("Error opening file %s: %v", file.Name(), err) + log.Errorf("Error opening file %s: %v", file, err) continue } - defer file.Close() + defer fp.Close() - key := filepath.Join(prefix, strings.TrimPrefix(file.Name(), baseDirParentPath)) + key := filepath.Join(prefix, strings.TrimPrefix(file, baseDirParentPath)) _, err = client.PutObject(&s3.PutObjectInput{ Bucket: aws.String(bucket), Key: aws.String(key), - Body: file, + Body: fp, }) if err != nil { - log.Errorf("Error uploading file %s: %v", file.Name(), err) + log.Errorf("Error uploading file %s: %v", file, err) continue } successFiles += 1 - log.Infof("Uploaded %s to S3://%s/%s", file.Name(), bucket, key) + log.Infof("Uploaded %s to S3://%s/%s", file, bucket, key) } return totalFiles, totalDirs, successFiles