mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 05:12:10 +00:00
parent
6ec5dc8016
commit
2cd9c7ef16
@ -138,8 +138,7 @@ func Open(cfg Config) (*SFTP, error) {
|
|||||||
|
|
||||||
func (r *SFTP) mkdirAllDataSubdirs() error {
|
func (r *SFTP) mkdirAllDataSubdirs() error {
|
||||||
for _, d := range r.Paths() {
|
for _, d := range r.Paths() {
|
||||||
err := r.mkdirAll(d, backend.Modes.Dir)
|
err := r.c.MkdirAll(d)
|
||||||
debug.Log("mkdirAll %v -> %v", d, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -250,38 +249,6 @@ func (r *SFTP) Location() string {
|
|||||||
return r.p
|
return r.p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SFTP) mkdirAll(dir string, mode os.FileMode) error {
|
|
||||||
// check if directory already exists
|
|
||||||
fi, err := r.c.Lstat(dir)
|
|
||||||
if err == nil {
|
|
||||||
if fi.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.Errorf("mkdirAll(%s): entry exists but is not a directory", dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
// create parent directories
|
|
||||||
errMkdirAll := r.mkdirAll(path.Dir(dir), backend.Modes.Dir)
|
|
||||||
|
|
||||||
// create directory
|
|
||||||
errMkdir := r.c.Mkdir(dir)
|
|
||||||
|
|
||||||
// test if directory was created successfully
|
|
||||||
fi, err = r.c.Lstat(dir)
|
|
||||||
if err != nil {
|
|
||||||
// return previous errors
|
|
||||||
return errors.Errorf("mkdirAll(%s): unable to create directories: %v, %v", dir, errMkdirAll, errMkdir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !fi.IsDir() {
|
|
||||||
return errors.Errorf("mkdirAll(%s): entry exists but is not a directory", dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
// set mode
|
|
||||||
return r.c.Chmod(dir, mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Join joins the given paths and cleans them afterwards. This always uses
|
// Join joins the given paths and cleans them afterwards. This always uses
|
||||||
// forward slashes, which is required by sftp.
|
// forward slashes, which is required by sftp.
|
||||||
func Join(parts ...string) string {
|
func Join(parts ...string) string {
|
||||||
@ -306,7 +273,7 @@ func (r *SFTP) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader
|
|||||||
|
|
||||||
if r.IsNotExist(err) {
|
if r.IsNotExist(err) {
|
||||||
// error is caused by a missing directory, try to create it
|
// error is caused by a missing directory, try to create it
|
||||||
mkdirErr := r.mkdirAll(r.Dirname(h), backend.Modes.Dir)
|
mkdirErr := r.c.MkdirAll(r.Dirname(h))
|
||||||
if mkdirErr != nil {
|
if mkdirErr != nil {
|
||||||
debug.Log("error creating dir %v: %v", r.Dirname(h), mkdirErr)
|
debug.Log("error creating dir %v: %v", r.Dirname(h), mkdirErr)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user