mirror of
https://github.com/kopia/kopia.git
synced 2026-05-07 22:32:45 -04:00
repo: fixed race condition during Open() where we may read incomplete file
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/natefinch/atomic"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/kopia/kopia/repo/blob"
|
||||
@@ -196,7 +198,7 @@ func readAndCacheFormatBlobBytes(ctx context.Context, st blob.Storage, cacheDire
|
||||
}
|
||||
|
||||
if cacheDirectory != "" {
|
||||
if err := ioutil.WriteFile(cachedFile, b, 0600); err != nil {
|
||||
if err := atomic.WriteFile(cachedFile, bytes.NewReader(b)); err != nil {
|
||||
log(ctx).Warningf("warning: unable to write cache: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user