From 3062de6187990f9b4f669ecd9dffdd48ee0d778f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 11 Jul 2017 23:19:58 +0200 Subject: fusefronted: enable writing to write-only files Due to RMW, we always need read permissions on the backing file. This is a problem if the file permissions do not allow reading (i.e. 0200 permissions). This patch works around that problem by chmod'ing the file, obtaining a fd, and chmod'ing it back. Test included. Issue reported at: https://github.com/rfjakob/gocryptfs/issues/125 --- tests/defaults/main_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/defaults') diff --git a/tests/defaults/main_test.go b/tests/defaults/main_test.go index ca11b43..5c6bb84 100644 --- a/tests/defaults/main_test.go +++ b/tests/defaults/main_test.go @@ -4,6 +4,7 @@ package defaults import ( "bytes" "io" + "io/ioutil" "os" "os/exec" "runtime" @@ -161,3 +162,32 @@ func TestXfs124(t *testing.T) { wg.Wait() } + +func TestWrite0200File(t *testing.T) { + fn := test_helpers.DefaultPlainDir + "/TestWrite0200File" + err := ioutil.WriteFile(fn, nil, 0200) + if err != nil { + t.Fatalf("creating empty file failed: %v", err) + } + fd, err := os.OpenFile(fn, os.O_WRONLY, 0) + if err != nil { + t.Fatal(err) + } + fi, err := fd.Stat() + if err != nil { + t.Fatal(err) + } + perms := fi.Mode().Perm() + if perms != 0200 { + t.Fatal("wrong initial permissions") + } + defer fd.Close() + _, err = fd.Write(make([]byte, 10)) + if err != nil { + t.Fatal(err) + } + perms = fi.Mode().Perm() + if perms != 0200 { + t.Fatal("wrong restored permissions") + } +} -- cgit v1.2.3