package backblaze import ( "context" "fmt" "strconv" "github.com/rclone/rclone/backend/b2" "github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/operations" ) func (b *BackBlaze) CleanUp(ctx context.Context, cancel context.CancelFunc, bucketName string) error { var dups []duplicate var err error if bucketName != "" { dups, err = b.listDuplicatesFromBucket(ctx, cancel, b.b2Client, bucketName) if err != nil { return fmt.Errorf("b.listDuplicatesFromBucket: %w", err) } } else { dups, err = b.listDuplicates(ctx, cancel, b.b2Client) if err != nil { return fmt.Errorf("b.listDuplicates: %w", err) } } if len(dups) <= 0 { return nil } smpl := configmap.Simple{} smpl.Set("account", b.bbID) smpl.Set("key", b.bbKey) smpl.Set("chunk_size", strconv.FormatInt(int64(9600), 10)) b.logger.Infoln("duplicates", len(dups)) for _, d := range dups { f, err := b2.NewFs(ctx, "B2", d.dir(), smpl) if err != nil { return fmt.Errorf("rclonefs.NewFs %w", err) } if err := operations.CleanUp(ctx, f); err != nil { return fmt.Errorf("operations.CleanUp %w", err) } b.logger.Infoln(d.dir(), "cleaned up") } return nil }