fix: sync create longRunningCtx
This commit is contained in:
parent
cd88fd2668
commit
66cd459306
|
@ -18,6 +18,7 @@ var Sync = &cobra.Command{
|
|||
Short: "Sync files or directories to Backblaze",
|
||||
Long: `A tool to backup files and directories to Backblaze.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
ctx, cancel := context.WithCancel(signalContext(cmd.Context()))
|
||||
defer cancel()
|
||||
|
||||
|
|
|
@ -43,7 +43,11 @@ func (b *BackBlaze) Sync(ctx context.Context) error {
|
|||
}
|
||||
|
||||
if b.options.Dir != "" {
|
||||
oldFiles, err := b.bucketFiles(ctx, bc)
|
||||
// Create a separate context for long-running operations
|
||||
longRunningCtx, cancelLongRunningOps := context.WithCancel(context.Background())
|
||||
defer cancelLongRunningOps()
|
||||
|
||||
oldFiles, err := b.bucketFiles(longRunningCtx, bc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bucketFiles %w", err)
|
||||
}
|
||||
|
@ -60,7 +64,7 @@ func (b *BackBlaze) Sync(ctx context.Context) error {
|
|||
go func() {
|
||||
defer wg.Done()
|
||||
for src := range fileChan {
|
||||
if err := b.copyFile(ctx, bc, src); err != nil {
|
||||
if err := b.copyFile(longRunningCtx, bc, src); err != nil {
|
||||
b.logger.Errorf("error copying file %s: %v\n", src, err)
|
||||
continue
|
||||
}
|
||||
|
@ -87,7 +91,7 @@ func (b *BackBlaze) Sync(ctx context.Context) error {
|
|||
wg.Wait()
|
||||
|
||||
// Cleanup old files after backup is completed
|
||||
if err := b.cleanBucket(ctx, bc, oldFiles); err != nil {
|
||||
if err := b.cleanBucket(longRunningCtx, bc, oldFiles); err != nil {
|
||||
return fmt.Errorf("cleanBucket %w", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue