Исправление некоторых багов
This commit is contained in:
6
api.go
6
api.go
@@ -440,8 +440,9 @@ func (a *Agate) GetRemoteSnapshot(ctx context.Context, address string, snapshotI
|
|||||||
|
|
||||||
if localParentID != "" {
|
if localParentID != "" {
|
||||||
if err := a.manager.ExtractSnapshot(ctx, localParentID, newSnapshotDir, false); err != nil {
|
if err := a.manager.ExtractSnapshot(ctx, localParentID, newSnapshotDir, false); err != nil {
|
||||||
a.options.Logger.Printf("Warning: failed to extract local parent snapshot %s: %v", localParentID, err)
|
return fmt.Errorf("failed to extract local parent snapshot %s for diff application: %w", localParentID, err)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
localParentSnap, err := a.GetSnapshotDetails(ctx, localParentID)
|
localParentSnap, err := a.GetSnapshotDetails(ctx, localParentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.options.Logger.Printf("Warning: failed to get local parent details %s: %v", localParentID, err)
|
a.options.Logger.Printf("Warning: failed to get local parent details %s: %v", localParentID, err)
|
||||||
@@ -461,7 +462,6 @@ func (a *Agate) GetRemoteSnapshot(ctx context.Context, address string, snapshotI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
diffArchivePath := filepath.Join(tempDownloadDir, snapshotID+"_diff.zip")
|
diffArchivePath := filepath.Join(tempDownloadDir, snapshotID+"_diff.zip")
|
||||||
diffPartPath := diffArchivePath + ".part"
|
diffPartPath := diffArchivePath + ".part"
|
||||||
|
|||||||
@@ -395,6 +395,12 @@ func (data *SnapshotManagerData) ExtractSnapshot(ctx context.Context, snapshotID
|
|||||||
|
|
||||||
// If cleanTarget is true, clean the target directory before extraction
|
// If cleanTarget is true, clean the target directory before extraction
|
||||||
if cleanTarget {
|
if cleanTarget {
|
||||||
|
rc, err := zip.OpenReader(blobPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("snapshot archive is corrupted or unreadable, restore aborted to protect data: %w", err)
|
||||||
|
}
|
||||||
|
rc.Close()
|
||||||
|
|
||||||
// Remove the directory and recreate it
|
// Remove the directory and recreate it
|
||||||
if err := os.RemoveAll(path); err != nil {
|
if err := os.RemoveAll(path); err != nil {
|
||||||
return fmt.Errorf("failed to clean target directory: %w", err)
|
return fmt.Errorf("failed to clean target directory: %w", err)
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ func (fs *fileSystemStore) getBlobPath(snapshotID string) string {
|
|||||||
// StoreBlob сохраняет данные из reader в файл в baseDir.
|
// StoreBlob сохраняет данные из reader в файл в baseDir.
|
||||||
func (fs *fileSystemStore) StoreBlob(ctx context.Context, snapshotID string, reader io.Reader) (string, error) {
|
func (fs *fileSystemStore) StoreBlob(ctx context.Context, snapshotID string, reader io.Reader) (string, error) {
|
||||||
blobPath := fs.getBlobPath(snapshotID)
|
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 {
|
if err != nil {
|
||||||
file.Close()
|
file.Close()
|
||||||
os.Remove(tempPath) // Удаляем мусор
|
os.Remove(tempPath) // Удаляем мусор
|
||||||
@@ -107,13 +106,10 @@ func (fs *fileSystemStore) StoreBlob(ctx context.Context, snapshotID string, rea
|
|||||||
file.Close() // Закрываем перед переименованием
|
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)
|
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
|
return blobPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user