summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-07-15 12:00:08 +0200
committerJakob Unterwurzacher2018-07-15 12:02:39 +0200
commitbbf5b72fff8b07251faacce9e77dd427a4379081 (patch)
treeee7da7a4ba45cc51906c97f812d84d6812feace2
parentbcca323cb778d3ab9bf3b16e041ede5e67b18ff8 (diff)
WriteDirIV: delete incomplete gocryptfs.diriv file if write fails
If the underlying filesystem is full, writing to gocryptfs.diriv may fail, and later fsck show this: OpenDir "xyz": could not read gocryptfs.diriv: wanted 16 bytes, got 0 Uncovered by xfstests generic/083. Also fixes a fd leak in the error path.
-rw-r--r--internal/nametransform/diriv.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/nametransform/diriv.go b/internal/nametransform/diriv.go
index 10f3226..d67a5fa 100644
--- a/internal/nametransform/diriv.go
+++ b/internal/nametransform/diriv.go
@@ -99,12 +99,17 @@ func WriteDirIV(dirfd *os.File, dir string) error {
fd := os.NewFile(uintptr(fdRaw), file)
_, err = fd.Write(iv)
if err != nil {
+ fd.Close()
tlog.Warn.Printf("WriteDirIV: Write: %v", err)
+ // Delete incomplete gocryptfs.diriv file
+ syscallcompat.Unlinkat(int(dirfd.Fd()), file, 0)
return err
}
err = fd.Close()
if err != nil {
tlog.Warn.Printf("WriteDirIV: Close: %v", err)
+ // Delete incomplete gocryptfs.diriv file
+ syscallcompat.Unlinkat(int(dirfd.Fd()), file, 0)
return err
}
return nil