tests: add 1980.tar.gz extract test
Test that we get the right timestamp when extracting a tarball. Also simplify the workaround in doTestUtimesNano() and fix the fact that it was running no test at all.
This commit is contained in:
parent
600ceece35
commit
589748548f
@ -386,19 +386,20 @@ func (f *file) GetAttr(a *fuse.Attr) fuse.Status {
|
||||
return fuse.OK
|
||||
}
|
||||
|
||||
// BrokenAtimeOmit means that atime support is broken.
|
||||
// BrokenAtime means that atime support is broken.
|
||||
// TODO drop this once https://github.com/hanwen/go-fuse/pull/131 is
|
||||
// merged
|
||||
const BrokenAtimeOmit = true
|
||||
const BrokenAtime = true
|
||||
|
||||
func (f *file) Utimens(a *time.Time, m *time.Time) fuse.Status {
|
||||
if BrokenAtimeOmit {
|
||||
// Band-aid for a nil pointer crash, described in
|
||||
// https://github.com/rfjakob/gocryptfs/issues/48
|
||||
// Also band-aid for "mtime gets set to atime".
|
||||
//
|
||||
// TODO drop this once https://github.com/hanwen/go-fuse/pull/131 is
|
||||
// merged
|
||||
if BrokenAtime {
|
||||
if m == nil {
|
||||
tlog.Warn.Printf("refusing to set the atime to prevent a crash in go-fuse")
|
||||
return fuse.EINVAL
|
||||
}
|
||||
// Due to a bug in loopbackFile.Utimens, the "a" value will be used
|
||||
// to set both mtime and atime. Because mtime is more important, we
|
||||
// override "a".
|
||||
a = m
|
||||
}
|
||||
f.fdLock.RLock()
|
||||
|
@ -3,6 +3,7 @@ package defaults
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
@ -15,3 +16,22 @@ func TestMain(m *testing.M) {
|
||||
test_helpers.UnmountPanic(test_helpers.DefaultPlainDir)
|
||||
os.Exit(r)
|
||||
}
|
||||
|
||||
// Test that we get the right timestamp when extracting a tarball.
|
||||
func Test1980Tar(t *testing.T) {
|
||||
c := exec.Command("tar", "xzf", "1980.tar.gz", "-C", test_helpers.DefaultPlainDir)
|
||||
c.Stderr = os.Stderr
|
||||
c.Stdout = os.Stdout
|
||||
err := c.Run()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fi, err := os.Stat(test_helpers.DefaultPlainDir + "/1980.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := fi.ModTime().Unix()
|
||||
if m != 315619323 {
|
||||
t.Errorf("Wrong mtime: %d", m)
|
||||
}
|
||||
}
|
||||
|
@ -660,21 +660,10 @@ type utimesTestcaseStruct struct {
|
||||
func compareUtimes(want [2]syscall.Timespec, actual [2]syscall.Timespec) error {
|
||||
tsNames := []string{"atime", "mtime"}
|
||||
for i := range want {
|
||||
if fusefrontend.BrokenAtimeOmit && i == 0 {
|
||||
// Don't check atime. It's broken in go-fuse.
|
||||
// TODO remove this once the pull request is merged:
|
||||
// https://github.com/hanwen/go-fuse/pull/131
|
||||
continue
|
||||
}
|
||||
if want[i].Sec != actual[i].Sec {
|
||||
return fmt.Errorf("Wrong %s seconds: want=%d actual=%d", tsNames[i], want[i].Sec, actual[i].Sec)
|
||||
}
|
||||
if want[i].Nsec != actual[i].Nsec {
|
||||
if actual[i].Nsec == 0 {
|
||||
// TODO remove this once the pull request is merged:
|
||||
// https://github.com/hanwen/go-fuse/pull/131
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("Wrong %s nanoseconds: want=%d actual=%d", tsNames[i], want[i].Nsec, actual[i].Nsec)
|
||||
}
|
||||
}
|
||||
@ -687,6 +676,10 @@ const _UTIME_OMIT = ((1 << 30) - 2)
|
||||
// works correctly. Pass "/proc/self/fd/N" to test a file descriptor.
|
||||
func doTestUtimesNano(t *testing.T, path string) {
|
||||
utimeTestcases := []utimesTestcaseStruct{
|
||||
{
|
||||
in: [2]syscall.Timespec{{Sec: 50, Nsec: 0}, {Sec: 50, Nsec: 0}},
|
||||
out: [2]syscall.Timespec{{Sec: 50, Nsec: 0}, {Sec: 50, Nsec: 0}},
|
||||
},
|
||||
{
|
||||
in: [2]syscall.Timespec{{Sec: 1, Nsec: 2}, {Sec: 3, Nsec: 4}},
|
||||
out: [2]syscall.Timespec{{Sec: 1, Nsec: 2}, {Sec: 3, Nsec: 4}},
|
||||
@ -703,7 +696,7 @@ func doTestUtimesNano(t *testing.T, path string) {
|
||||
if fusefrontend.BrokenAtimeOmit {
|
||||
// TODO remove this once the pull request is merged:
|
||||
// https://github.com/hanwen/go-fuse/pull/131
|
||||
utimeTestcases = utimeTestcases[0:0]
|
||||
utimeTestcases = utimeTestcases[:1]
|
||||
}
|
||||
for i, tc := range utimeTestcases {
|
||||
err := syscall.UtimesNano(path, tc.in[:])
|
||||
|
Loading…
Reference in New Issue
Block a user