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.
This commit is contained in:
parent
bcca323cb7
commit
bbf5b72fff
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user