mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 11:28:54 +00:00
Merge pull request #1333 from restic/fix-1328
Do not cache invalid/truncated files
This commit is contained in:
commit
a5c003acb0
12
internal/cache/file.go
vendored
12
internal/cache/file.go
vendored
@ -60,7 +60,7 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser,
|
|||||||
if fi.Size() <= crypto.Extension {
|
if fi.Size() <= crypto.Extension {
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
_ = c.Remove(h)
|
_ = c.Remove(h)
|
||||||
return nil, errors.New("cached file is truncated, removing")
|
return nil, errors.Errorf("cached file %v is truncated, removing", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
@ -111,13 +111,21 @@ func (c *Cache) Save(h restic.Handle, rd io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = io.Copy(f, rd); err != nil {
|
n, err := io.Copy(f, rd)
|
||||||
|
if err != nil {
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
_ = c.Remove(h)
|
_ = c.Remove(h)
|
||||||
return errors.Wrap(err, "Copy")
|
return errors.Wrap(err, "Copy")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if n <= crypto.Extension {
|
||||||
|
_ = f.Close()
|
||||||
|
_ = c.Remove(h)
|
||||||
|
return errors.Errorf("trying to cache truncated file %v", h)
|
||||||
|
}
|
||||||
|
|
||||||
if err = f.Close(); err != nil {
|
if err = f.Close(); err != nil {
|
||||||
|
_ = c.Remove(h)
|
||||||
return errors.Wrap(err, "Close")
|
return errors.Wrap(err, "Close")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +378,8 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
|
|||||||
worker := func(ctx context.Context, id restic.ID) error {
|
worker := func(ctx context.Context, id restic.ID) error {
|
||||||
idx, err := LoadIndex(ctx, r, id)
|
idx, err := LoadIndex(ctx, r, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
fmt.Fprintf(os.Stderr, "%v, ignoring\n", err)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user