mirror of
https://github.com/restic/restic.git
synced 2025-10-11 04:19:58 +00:00
restore: let filerestorer also handle empty files
This get's rid of the corresponding special cases.
This commit is contained in:
@@ -120,6 +120,13 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error {
|
||||
// create packInfo from fileInfo
|
||||
for _, file := range r.files {
|
||||
fileBlobs := file.blobs.(restic.IDs)
|
||||
if len(fileBlobs) == 0 {
|
||||
err := r.restoreEmptyFileAt(file.location)
|
||||
if errFile := r.sanitizeError(file, err); errFile != nil {
|
||||
return errFile
|
||||
}
|
||||
}
|
||||
|
||||
largeFile := len(fileBlobs) > largeFileBlobCount
|
||||
var packsMap map[restic.ID][]fileBlobInfo
|
||||
if largeFile {
|
||||
@@ -195,6 +202,21 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error {
|
||||
return wg.Wait()
|
||||
}
|
||||
|
||||
func (r *fileRestorer) restoreEmptyFileAt(location string) error {
|
||||
f, err := createFile(r.targetPath(location), 0, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if r.progress != nil {
|
||||
r.progress.AddProgress(location, 0, 0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type blobToFileOffsetsMapping map[restic.ID]struct {
|
||||
files map[*fileInfo][]int64 // file -> offsets (plural!) of the blob in the file
|
||||
blob restic.Blob
|
||||
|
Reference in New Issue
Block a user