Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 82f1273

Browse files
authoredFeb 20, 2025··
fix: resolve the push error occurred in some cases (#75)
Signed-off-by: chlins <[email protected]>
1 parent b0c7fa1 commit 82f1273

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎pkg/backend/push.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24+
"io"
2425

2526
"github.com/CloudNativeAI/modctl/pkg/storage"
2627

@@ -157,9 +158,11 @@ func pushIfNotExist(ctx context.Context, pb *ProgressBar, prompt string, src sto
157158
return fmt.Errorf("failed to fetch the content from source: %w", err)
158159
}
159160

160-
defer content.Close()
161-
162-
if err := dst.Blobs().Push(ctx, desc, pb.Add(prompt, desc, content)); err != nil {
161+
// resolve issue: https://github.com/CloudNativeAI/modctl/issues/50
162+
// wrap the content to the NopCloser, because the implementation of the distribution will
163+
// always return the error when Close() is called.
164+
// refer: https://github.com/distribution/distribution/blob/63d3892315c817c931b88779399a8e9142899a8e/registry/storage/filereader.go#L105
165+
if err := dst.Blobs().Push(ctx, desc, pb.Add(prompt, desc, io.NopCloser(content))); err != nil {
163166
pb.Abort(desc)
164167
return err
165168
}

0 commit comments

Comments
 (0)
Please sign in to comment.