2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 19:49:44 +00:00

s3/local backend: Fix error for overwriting files

This commit is contained in:
Alexander Neumann 2016-01-24 21:13:24 +01:00
parent 1547d3b656
commit d9c87559b5
2 changed files with 16 additions and 5 deletions

View File

@ -171,16 +171,19 @@ func (b *Local) Save(h backend.Handle, p []byte) (err error) {
f := filename(b.p, h.Type, h.Name)
// create directories if necessary, ignore errors
if h.Type == backend.Data {
os.MkdirAll(filepath.Dir(f), backend.Modes.Dir)
}
// test if new path already exists
if _, err := os.Stat(f); err == nil {
return fmt.Errorf("Rename(): file %v already exists", f)
}
// create directories if necessary, ignore errors
if h.Type == backend.Data {
err = os.MkdirAll(filepath.Dir(f), backend.Modes.Dir)
if err != nil {
return err
}
}
err = os.Rename(tmpfile.Name(), f)
debug.Log("local.Save", "save %v: rename %v -> %v: %v",
h, filepath.Base(tmpfile.Name()), filepath.Base(f), err)

View File

@ -2,6 +2,7 @@ package s3
import (
"bytes"
"errors"
"io"
"strings"
@ -103,6 +104,13 @@ func (be S3Backend) Save(h backend.Handle, p []byte) (err error) {
path := s3path(h.Type, h.Name)
// Check key does not already exist
_, err = be.client.StatObject(be.bucketname, path)
if err == nil {
debug.Log("s3.blob.Finalize()", "%v already exists", h)
return errors.New("key already exists")
}
<-be.connChan
defer func() {
be.connChan <- struct{}{}