itest: move all test db files when using both etcd and bbolt
In some tests we moved channeld.db to a temp location in order to "time travel". This commit extends the existing semantics by moving all files, including embedded etcd db too besides the channeld.db file.
This commit is contained in:
3 files changed
+66
-18
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -1403,3 +1404,47 @@ func CopyFile(dest, src string) error {
|
||||
|
||||
return d.Close()
|
||||
}
|
||||
|
||||
// FileExists returns true if the file at path exists.
|
||||
func FileExists(path string) bool {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// CopyAll copies all files and directories from srcDir to dstDir recursively.
|
||||
// Note that this function does not support links.
|
||||
func CopyAll(dstDir, srcDir string) error {
|
||||
entries, err := ioutil.ReadDir(srcDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
srcPath := filepath.Join(srcDir, entry.Name())
|
||||
dstPath := filepath.Join(dstDir, entry.Name())
|
||||
|
||||
info, err := os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
err := os.Mkdir(dstPath, info.Mode())
|
||||
if err != nil && !os.IsExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = CopyAll(dstPath, srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err := CopyFile(dstPath, srcPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user