mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-07 14:28:27 +00:00
fixup alterFiles
This commit is contained in:
parent
44d0da02d0
commit
d114648c16
28
test/util.go
28
test/util.go
@ -114,7 +114,7 @@ func alterFiles(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
info, err = os.Stat(path);
|
||||
info, err = os.Stat(path)
|
||||
if err != nil {
|
||||
// Something we deleted while walking. Ignore.
|
||||
return nil
|
||||
@ -131,17 +131,24 @@ func alterFiles(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
r := rand.Float64()
|
||||
// File structure is base/x/xy/xyz12345...
|
||||
// comps == 1: base (don't touch)
|
||||
// comps == 2: base/x (must be dir)
|
||||
// comps == 3: base/x/xy (must be dir)
|
||||
// comps > 3: base/x/xy/xyz12345... (can be dir or file)
|
||||
|
||||
comps := len(strings.Split(path, string(os.PathSeparator)))
|
||||
|
||||
r := rand.Intn(10)
|
||||
switch {
|
||||
case r < 0.1 && comps > 2:
|
||||
case r == 0 && comps > 2:
|
||||
// Delete every tenth file or directory, except top levels
|
||||
err := removeAll(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case r < 0.2 && info.Mode().IsRegular():
|
||||
case r == 1 && info.Mode().IsRegular():
|
||||
if info.Mode()&0200 != 0200 {
|
||||
// Not owner writable. Fix.
|
||||
err = os.Chmod(path, 0644)
|
||||
@ -169,13 +176,14 @@ func alterFiles(dir string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case r < 0.3 && comps > 2 && rand.Float64() < 0.2:
|
||||
|
||||
case r == 2 && comps > 3 && rand.Float64() < 0.2:
|
||||
if !info.Mode().IsRegular() {
|
||||
err = removeAll(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d1 := []byte("I used to be a dir: "+path)
|
||||
d1 := []byte("I used to be a dir: " + path)
|
||||
err := ioutil.WriteFile(path, d1, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -189,9 +197,10 @@ func alterFiles(dir string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
generateFiles(path, 100, 20, "../LICENSE")
|
||||
generateFiles(path, 10, 20, "../LICENSE")
|
||||
}
|
||||
case r < 0.3 && comps > 1 && (info.Mode().IsRegular() || rand.Float64() < 0.2):
|
||||
|
||||
case r == 3 && comps > 2 && (info.Mode().IsRegular() || rand.Float64() < 0.2):
|
||||
rpath := filepath.Dir(path)
|
||||
if rand.Float64() < 0.2 {
|
||||
for move := rand.Intn(comps - 1); move > 0; move-- {
|
||||
@ -209,8 +218,7 @@ func alterFiles(dir string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create 100 new files
|
||||
return generateFiles(dir, 100, 20, "../LICENSE")
|
||||
return generateFiles(dir, 25, 20, "../LICENSE")
|
||||
}
|
||||
|
||||
func ReadRand(bs []byte) (int, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user