Попытка исправления загрузки локального блоба
This commit is contained in:
32
api.go
32
api.go
@@ -487,19 +487,29 @@ func (ag *Agate) RegisterLocalSnapshot(ctx context.Context, snapshotID, parentID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Add the file to the blob store
|
// 2. Add the file to the blob store
|
||||||
localFile, err := os.Open(localPath)
|
// Check if blob already exists. If so, we assume it's the correct one and skip overwriting.
|
||||||
if err != nil {
|
// This is to prevent issues when registering a file that is already in the blob store.
|
||||||
return fmt.Errorf("failed to open local snapshot file: %w", err)
|
_, err = ag.options.BlobStore.GetBlobPath(ctx, snapshotID)
|
||||||
}
|
if err == nil {
|
||||||
defer func() {
|
ag.options.Logger.Printf("blob for snapshot %s already exists, skipping storing it", snapshotID)
|
||||||
if err := localFile.Close(); err != nil {
|
} else if errors.Is(err, models.ErrNotFound) {
|
||||||
ag.options.Logger.Printf("ERROR: failed to close local file: %v", err)
|
// Blob does not exist, so we store it.
|
||||||
|
localFile, err := os.Open(localPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open local snapshot file: %w", err)
|
||||||
}
|
}
|
||||||
}()
|
defer func() {
|
||||||
|
if err := localFile.Close(); err != nil {
|
||||||
|
ag.options.Logger.Printf("ERROR: failed to close local file: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
_, err = ag.options.BlobStore.StoreBlob(ctx, snapshotID, localFile)
|
if _, err = ag.options.BlobStore.StoreBlob(ctx, snapshotID, localFile); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("failed to store blob from local file: %w", err)
|
||||||
return fmt.Errorf("failed to store blob from local file: %w", err)
|
}
|
||||||
|
} else {
|
||||||
|
// Another error occurred when checking for the blob.
|
||||||
|
return fmt.Errorf("failed to check for existing blob: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Create and save snapshot metadata
|
// 3. Create and save snapshot metadata
|
||||||
|
|||||||
Reference in New Issue
Block a user