From ecc3d7fa64b60d83ca31ea4e48a13e487e749fa1 Mon Sep 17 00:00:00 2001 From: Urko Date: Tue, 29 Aug 2023 11:40:07 +0200 Subject: [PATCH] fix: check report bug --- cmd/check.go | 4 ++-- internal/services/backblaze/check.go | 12 ++++++++---- internal/services/backblaze/cleanup.go | 4 ++-- internal/services/backblaze/duplicates.go | 6 +++--- internal/services/backblaze/sync.go | 16 ++++++++-------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cmd/check.go b/cmd/check.go index 0d2dc49..2e4ac8f 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -122,11 +122,11 @@ var Check = &cobra.Command{ } } - if countNotInCloud > 0 { + if countNotInLocal > 0 { reportBuilder.WriteString("\n") reportBuilder.WriteString(cloudBuilder.String()) } - if countNotInLocal > 0 { + if countNotInCloud > 0 { reportBuilder.WriteString("\n") reportBuilder.WriteString(localBuilder.String()) } diff --git a/internal/services/backblaze/check.go b/internal/services/backblaze/check.go index 1e595ab..6aa861e 100644 --- a/internal/services/backblaze/check.go +++ b/internal/services/backblaze/check.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io/fs" + "path" "path/filepath" "sync" @@ -56,8 +57,10 @@ func (b *BackBlaze) b2BucketFiles(ctx context.Context, bucketName string, fileCh if bucketIter.Object() == nil { return errors.New("bucketIter Object is nil") } - b.logger.Debug("bucket file: ", bucketIter.Object().Name()) - fileChan <- bucketIter.Object().Name() + + // Retrieve just filename + b.logger.Debugln("bucket file: ", path.Base(bucketIter.Object().Name())) + fileChan <- path.Base(bucketIter.Object().Name()) } return nil @@ -93,7 +96,7 @@ func (b *BackBlaze) CompareConcurrent(ctx context.Context, backupDir, bucketName if _, ok := localFiles[f]; ok { panic(fmt.Errorf("local file already exists in map: %s", f)) } - b.logger.Debug("local file ", f) + b.logger.Debugln("local file ", f) localFiles[f]++ } }() @@ -114,7 +117,7 @@ func (b *BackBlaze) CompareConcurrent(ctx context.Context, backupDir, bucketName if _, ok := cloudFiles[f]; ok { panic(fmt.Errorf("cloud file already exists in map: %s", f)) } - b.logger.Debug("B2 file ", f) + b.logger.Debugln("B2 file ", f) cloudFiles[f]++ } }() @@ -143,6 +146,7 @@ func (b *BackBlaze) CompareConcurrent(ctx context.Context, backupDir, bucketName go func() { defer wg.Done() for cloudFile := range cloudFiles { + b.logger.Debugln("cloudFile ", cloudFile) if _, exists := localFiles[cloudFile]; !exists { msgChan <- B2Local{File: cloudFile, Err: ErrCloudNotInLocal} } diff --git a/internal/services/backblaze/cleanup.go b/internal/services/backblaze/cleanup.go index d07c5fb..f4b1a42 100644 --- a/internal/services/backblaze/cleanup.go +++ b/internal/services/backblaze/cleanup.go @@ -34,7 +34,7 @@ func (b *BackBlaze) CleanUp(ctx context.Context, cancel context.CancelFunc, buck smpl.Set("account", b.bbID) smpl.Set("key", b.bbKey) smpl.Set("chunk_size", strconv.FormatInt(int64(9600), 10)) - b.logger.Info("duplicates", len(dups)) + b.logger.Infoln("duplicates", len(dups)) for _, d := range dups { f, err := b2.NewFs(ctx, "B2", d.dir(), smpl) if err != nil { @@ -43,7 +43,7 @@ func (b *BackBlaze) CleanUp(ctx context.Context, cancel context.CancelFunc, buck if err := operations.CleanUp(ctx, f); err != nil { return fmt.Errorf("operations.CleanUp %w", err) } - b.logger.Info(d.dir(), "cleaned up") + b.logger.Infoln(d.dir(), "cleaned up") } return nil diff --git a/internal/services/backblaze/duplicates.go b/internal/services/backblaze/duplicates.go index 4f66282..8769994 100644 --- a/internal/services/backblaze/duplicates.go +++ b/internal/services/backblaze/duplicates.go @@ -72,20 +72,20 @@ func (b *BackBlaze) listDuplicates(ctx context.Context, cancel context.CancelFun bucketIter := bc.List(ctx, b2.ListHidden()) if bucketIter == nil { - b.logger.Error("bucket list cannot be nil") + b.logger.Errorln("bucket list cannot be nil") return } for { if !bucketIter.Next() { if bucketIter.Err() != nil { - b.logger.Error("bucketIter err %w", bucketIter.Err()) + b.logger.Errorf("bucketIter err %s", bucketIter.Err()) return } break } if bucketIter.Object() == nil { - b.logger.Error("bucketIter Object is nil") + b.logger.Errorln("bucketIter Object is nil") continue } files[bucketIter.Object().Name()]++ diff --git a/internal/services/backblaze/sync.go b/internal/services/backblaze/sync.go index 80d4f52..9245439 100644 --- a/internal/services/backblaze/sync.go +++ b/internal/services/backblaze/sync.go @@ -50,9 +50,9 @@ func (b *BackBlaze) Sync(ctx context.Context) error { if err != nil { return fmt.Errorf("bucketFiles %w", err) } - b.logger.Debug(strings.Repeat("*", 40)) - b.logger.Debug("oldFiles to clean:\n\t\t" + strings.Join(oldFiles, "\n\t\t")) - b.logger.Debug(strings.Repeat("*", 40)) + b.logger.Debugln(strings.Repeat("*", 40)) + b.logger.Debugln("oldFiles to clean:\n\t\t" + strings.Join(oldFiles, "\n\t\t")) + b.logger.Debugln(strings.Repeat("*", 40)) fileChan := make(chan string) @@ -95,7 +95,7 @@ func (b *BackBlaze) Sync(ctx context.Context) error { } } - b.logger.Info("copied successfully") + b.logger.Infoln("copied successfully") return nil } @@ -112,7 +112,7 @@ func (b *BackBlaze) copyFile(ctx context.Context, bucket *b2.Bucket, src string) w := bucket.Object(fi.Name()).NewWriter(ctx) w.ConcurrentUploads = writers w.UseFileBuffer = true - b.logger.Info("start copying", fi.Name()) + b.logger.Infoln("start copying ", fi.Name()) if _, err := io.Copy(w, f); err != nil { w.Close() return err @@ -121,7 +121,7 @@ func (b *BackBlaze) copyFile(ctx context.Context, bucket *b2.Bucket, src string) return err } - b.logger.Info("end copying", fi.Name()) + b.logger.Infoln("end copying ", fi.Name()) return nil } @@ -130,7 +130,7 @@ func (b *BackBlaze) cleanBucket(ctx context.Context, bucket *b2.Bucket, files [] for _, v := range files { obj := bucket.Object(v) if obj == nil { - b.logger.Error("bucket.Object is nil", v) + b.logger.Errorln("bucket.Object is nil", v) continue } if err := obj.Delete(ctx); err != nil { @@ -160,7 +160,7 @@ func (b *BackBlaze) bucketFiles(ctx context.Context, bucket *b2.Bucket) ([]strin break } if bucketIter.Object() == nil { - b.logger.Error("bucketIter Object is nil") + b.logger.Errorln("bucketIter Object is nil") continue } files = append(files, bucketIter.Object().Name())