Commit 408ce31f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

unionfs: skip rm -rf test if rm is older than v. 8.0

parent f0d19206
package unionfs package unionfs
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"strconv"
"syscall" "syscall"
"testing" "testing"
"time" "time"
...@@ -98,7 +101,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) { ...@@ -98,7 +101,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
return wd, func() { return wd, func() {
err := state.Unmount() err := state.Unmount()
if err != nil { if err != nil {
return return
} }
setRecursiveWritable(t, wd, true) setRecursiveWritable(t, wd, true)
os.RemoveAll(wd) os.RemoveAll(wd)
...@@ -893,8 +896,34 @@ func TestUnionFsRemoveAll(t *testing.T) { ...@@ -893,8 +896,34 @@ func TestUnionFsRemoveAll(t *testing.T) {
} }
} }
// Warning: test fails under coreutils < 8.0 because of non-posix behaviour func ProgramVersion(bin string) (major, minor int64, err error) {
// of the "rm" tool -- which relies on behaviour that doesn't work in fuse. cmd := exec.Command(bin, "--version")
buf := &bytes.Buffer{}
cmd.Stdout = buf
if err := cmd.Run(); err != nil {
return 0, 0, err
}
lines := strings.Split(buf.String(), "\n")
if len(lines) < 1 {
return 0, 0, fmt.Errorf("no output")
}
matches := regexp.MustCompile(".* ([0-9]+)\\.([0-9]+)").FindStringSubmatch(lines[0])
if matches == nil {
log.Println("no output")
return 0, 0, fmt.Errorf("no match for %q", lines[0])
}
major, err = strconv.ParseInt(matches[1], 10, 64)
if err != nil {
return 0, 0, err
}
minor, err = strconv.ParseInt(matches[2], 10, 64)
if err != nil {
return 0, 0, err
}
return major, minor, nil
}
func TestUnionFsRmRf(t *testing.T) { func TestUnionFsRmRf(t *testing.T) {
wd, clean := setupUfs(t) wd, clean := setupUfs(t)
defer clean() defer clean()
...@@ -916,6 +945,14 @@ func TestUnionFsRmRf(t *testing.T) { ...@@ -916,6 +945,14 @@ func TestUnionFsRmRf(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("LookPath failed: %v", err) t.Fatalf("LookPath failed: %v", err)
} }
maj, min, err := ProgramVersion(bin)
if err != nil {
t.Logf("ProgramVersion failed: %v", err)
}
if maj < 8 { // assuming GNU coreutils.
t.Skipf("Skipping test; GNU rm %d.%d is not POSIX compliant.", maj, min)
}
command := fmt.Sprintf("%s -f %s/mnt/dir", bin, wd) command := fmt.Sprintf("%s -f %s/mnt/dir", bin, wd)
log.Printf("Command: %s", command) log.Printf("Command: %s", command)
names, _ := Readdirnames(wd + "/mnt/dir") names, _ := Readdirnames(wd + "/mnt/dir")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment