Quellcode durchsuchen

download: handle inner errors

Michael Yang vor 1 Jahr
Ursprung
Commit
c413a55093
1 geänderte Dateien mit 10 neuen und 4 gelöschten Zeilen
  1. 10 4
      server/download.go

+ 10 - 4
server/download.go

@@ -31,11 +31,13 @@ type blobDownload struct {
 
 
 	Total     int64
 	Total     int64
 	Completed atomic.Int64
 	Completed atomic.Int64
-	done      bool
 
 
 	Parts []*blobDownloadPart
 	Parts []*blobDownloadPart
 
 
 	context.CancelFunc
 	context.CancelFunc
+
+	done       bool
+	err        error
 	references atomic.Int32
 	references atomic.Int32
 }
 }
 
 
@@ -125,7 +127,11 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
 	return nil
 	return nil
 }
 }
 
 
-func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *RegistryOptions) (err error) {
+func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *RegistryOptions) {
+	b.err = b.run(ctx, requestURL, opts)
+}
+
+func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *RegistryOptions) error {
 	defer blobDownloadManager.Delete(b.Digest)
 	defer blobDownloadManager.Delete(b.Digest)
 
 
 	ctx, b.CancelFunc = context.WithCancel(ctx)
 	ctx, b.CancelFunc = context.WithCancel(ctx)
@@ -285,8 +291,8 @@ func (b *blobDownload) Wait(ctx context.Context, fn func(api.ProgressResponse))
 			Completed: b.Completed.Load(),
 			Completed: b.Completed.Load(),
 		})
 		})
 
 
-		if b.done {
-			return nil
+		if b.done || b.err != nil {
+			return b.err
 		}
 		}
 	}
 	}
 }
 }