mirror of
https://github.com/ollama/ollama.git
synced 2026-04-17 21:54:08 +02:00
check with HEAD before upload
This commit is contained in:
@@ -150,14 +150,19 @@ func (u *uploader) uploadOnce(ctx context.Context, blob Blob) (int64, error) {
|
||||
u.logger.Debug("uploading blob", "digest", blob.Digest, "size", blob.Size)
|
||||
}
|
||||
|
||||
// Check if blob already exists (may have been uploaded by another
|
||||
// concurrent process since the initial HEAD check)
|
||||
if exists, err := u.exists(ctx, blob); err != nil {
|
||||
return 0, err
|
||||
} else if exists {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Init upload
|
||||
uploadURL, err := u.initUpload(ctx, blob)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if uploadURL == "" {
|
||||
return 0, nil // blob already exists
|
||||
}
|
||||
|
||||
// Open file
|
||||
f, err := os.Open(filepath.Join(u.srcDir, digestToPath(blob.Digest)))
|
||||
@@ -220,10 +225,6 @@ func (u *uploader) initUpload(ctx context.Context, blob Blob) (string, error) {
|
||||
return u.initUpload(ctx, blob)
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusCreated {
|
||||
return "", nil // blob already exists
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusAccepted {
|
||||
return "", fmt.Errorf("init: status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user