mirror of
https://github.com/restic/restic.git
synced 2025-01-03 13:45:20 +00:00
Add tests for bug #101
This commit is contained in:
parent
c9ee79fc54
commit
1bb82afcf6
4 changed files with 68 additions and 21 deletions
41
pipe/pipe.go
41
pipe/pipe.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -82,13 +83,13 @@ func isFile(fi os.FileInfo) bool {
|
||||||
|
|
||||||
var errCancelled = errors.New("walk cancelled")
|
var errCancelled = errors.New("walk cancelled")
|
||||||
|
|
||||||
func walk(basedir, path string, done chan struct{}, jobs chan<- Job, res chan<- Result) error {
|
func walk(basedir, dir string, done chan struct{}, jobs chan<- Job, res chan<- Result) error {
|
||||||
info, err := os.Lstat(path)
|
info, err := os.Lstat(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
relpath, _ := filepath.Rel(basedir, path)
|
relpath, _ := filepath.Rel(basedir, dir)
|
||||||
|
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
select {
|
select {
|
||||||
|
@ -99,15 +100,29 @@ func walk(basedir, path string, done chan struct{}, jobs chan<- Job, res chan<-
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
names, err := readDirNames(path)
|
names, err := readDirNames(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert breakpoint to allow testing behaviour with vanishing files
|
||||||
|
// between Readdir() and lstat()
|
||||||
|
debug.BreakIf("pipe.walk1", func() bool {
|
||||||
|
match, err := path.Match(os.Getenv("DEBUG_BREAK_PIPE"), relpath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if match {
|
||||||
|
debug.Log("break", "break pattern matches for %v\n", relpath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return match
|
||||||
|
})
|
||||||
|
|
||||||
entries := make([]<-chan Result, 0, len(names))
|
entries := make([]<-chan Result, 0, len(names))
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
subpath := filepath.Join(path, name)
|
subpath := filepath.Join(dir, name)
|
||||||
|
|
||||||
ch := make(chan Result, 1)
|
ch := make(chan Result, 1)
|
||||||
entries = append(entries, ch)
|
entries = append(entries, ch)
|
||||||
|
@ -122,6 +137,22 @@ func walk(basedir, path string, done chan struct{}, jobs chan<- Job, res chan<-
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert breakpoint to allow testing behaviour with vanishing files
|
||||||
|
// between walk and open
|
||||||
|
debug.BreakIf("pipe.walk2", func() bool {
|
||||||
|
p := filepath.Join(relpath, name)
|
||||||
|
|
||||||
|
match, err := path.Match(os.Getenv("DEBUG_BREAK_PIPE"), p)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if match {
|
||||||
|
debug.Log("break", "break pattern matches for %v\n", p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return match
|
||||||
|
})
|
||||||
|
|
||||||
if isDir(fi) {
|
if isDir(fi) {
|
||||||
err = walk(basedir, subpath, done, jobs, ch)
|
err = walk(basedir, subpath, done, jobs, ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
set -em
|
|
||||||
|
|
||||||
# setup restic
|
|
||||||
prepare
|
|
||||||
run restic init
|
|
||||||
|
|
||||||
# start backup, break before saving files
|
|
||||||
DEBUG_BREAK=Archiver.Snapshot run restic.debug backup "${BASE}/fake-data" && debug "done"
|
|
||||||
|
|
||||||
# remove file
|
|
||||||
rm -f "${BASE}/fake-data/0/0/9/37"
|
|
||||||
|
|
||||||
# resume backup
|
|
||||||
fg
|
|
||||||
|
|
||||||
cleanup
|
|
16
testsuite/test-backup-missing-file1.sh
Executable file
16
testsuite/test-backup-missing-file1.sh
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
set -em
|
||||||
|
|
||||||
|
# setup restic
|
||||||
|
prepare
|
||||||
|
run restic init
|
||||||
|
|
||||||
|
# start backup, break between readdir and lstat
|
||||||
|
DEBUG_BREAK=pipe.walk1 DEBUG_BREAK_PIPE="fake-data/0/0/9" run restic.debug backup "${BASE}/fake-data" && debug "done"
|
||||||
|
|
||||||
|
# remove file
|
||||||
|
rm -f "${BASE}/fake-data/0/0/9/37"
|
||||||
|
|
||||||
|
# resume backup
|
||||||
|
fg
|
||||||
|
|
||||||
|
cleanup
|
16
testsuite/test-backup-missing-file2.sh
Executable file
16
testsuite/test-backup-missing-file2.sh
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
set -em
|
||||||
|
|
||||||
|
# setup restic
|
||||||
|
prepare
|
||||||
|
run restic init
|
||||||
|
|
||||||
|
# start backup, break between walk and save
|
||||||
|
DEBUG_BREAK=pipe.walk2 DEBUG_BREAK_PIPE="fake-data/0/0/9/37" run restic.debug backup "${BASE}/fake-data" && debug "done"
|
||||||
|
|
||||||
|
# remove file
|
||||||
|
rm -f "${BASE}/fake-data/0/0/9/37"
|
||||||
|
|
||||||
|
# resume backup
|
||||||
|
fg
|
||||||
|
|
||||||
|
cleanup
|
Loading…
Reference in a new issue