Исправление некоторых багов
This commit is contained in:
@@ -71,7 +71,6 @@ func (fs *fileSystemStore) getBlobPath(snapshotID string) string {
|
||||
// StoreBlob сохраняет данные из reader в файл в baseDir.
|
||||
func (fs *fileSystemStore) StoreBlob(ctx context.Context, snapshotID string, reader io.Reader) (string, error) {
|
||||
blobPath := fs.getBlobPath(snapshotID)
|
||||
log.Printf("Starting to store blob for snapshot %s at %s", snapshotID, blobPath)
|
||||
|
||||
// Используем временный файл, чтобы не повредить (возможно) существующий валидный файл
|
||||
// если загрузка упадет на середине.
|
||||
@@ -90,7 +89,7 @@ func (fs *fileSystemStore) StoreBlob(ctx context.Context, snapshotID string, rea
|
||||
}
|
||||
|
||||
// Копируем данные
|
||||
written, err := io.Copy(file, pr)
|
||||
_, err = io.Copy(file, pr)
|
||||
if err != nil {
|
||||
file.Close()
|
||||
os.Remove(tempPath) // Удаляем мусор
|
||||
@@ -107,13 +106,10 @@ func (fs *fileSystemStore) StoreBlob(ctx context.Context, snapshotID string, rea
|
||||
file.Close() // Закрываем перед переименованием
|
||||
|
||||
// Переименовываем временный файл в финальный (атомарная операция)
|
||||
if err := os.Rename(tempPath, blobPath); err != nil {
|
||||
if err = os.Rename(tempPath, blobPath); err != nil {
|
||||
return "", fmt.Errorf("failed to rename temp file to final blob: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("Successfully stored blob for snapshot %s. Total size: %.2f MB",
|
||||
snapshotID, float64(written)/1024/1024)
|
||||
|
||||
return blobPath, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user