aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2026-09-01 22:35:45 +0200
committerJakob Unterwurzacher2026-09-01 22:38:37 +0200
commit842af4463989ee6808d397433e9aba8517e49c89 (patch)
tree0ca57f5a8e3bfcc153a58a5c40b57050463074e2
parentc7f1fe301a43604cb2eb9d67f389563e8734016c (diff)
fsync gocryptfs.diriv filesHEADmaster
There is a performance penalty here, but the alternative is potential data loss on a system crash / power outage as shown in https://github.com/rfjakob/gocryptfs/issues/1033 . Also deduplicate the code a little using goto. Fixes https://github.com/rfjakob/gocryptfs/issues/1033
-rw-r--r--internal/nametransform/diriv.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/internal/nametransform/diriv.go b/internal/nametransform/diriv.go
index 5dd4940..aaa65ee 100644
--- a/internal/nametransform/diriv.go
+++ b/internal/nametransform/diriv.go
@@ -83,16 +83,22 @@ func WriteDirIVAt(dirfd int) error {
if !syscallcompat.IsENOSPC(err) {
tlog.Warn.Printf("WriteDirIV: Write: %v", err)
}
- // Delete incomplete gocryptfs.diriv file
- syscallcompat.Unlinkat(dirfd, DirIVFilename, 0)
- return err
+ goto delete
+ }
+ err = f.Sync()
+ if err != nil {
+ tlog.Warn.Printf("WriteDirIV: Sync: %v", err)
+ goto delete
}
err = f.Close()
if err != nil {
tlog.Warn.Printf("WriteDirIV: Close: %v", err)
- // Delete incomplete gocryptfs.diriv file
- syscallcompat.Unlinkat(dirfd, DirIVFilename, 0)
- return err
+ goto delete
}
return nil
+
+delete:
+ // Delete potentially incomplete gocryptfs.diriv file
+ syscallcompat.Unlinkat(dirfd, DirIVFilename, 0)
+ return err
}