]> git.apps.os.sepia.ceph.com Git - fscrypt.git/commit
writeDataAtomic() fixes (#140)
authorebiggers <ebiggers@google.com>
Mon, 9 Sep 2019 20:41:32 +0000 (13:41 -0700)
committerJoseph Richey <joerichey@google.com>
Mon, 9 Sep 2019 20:41:32 +0000 (13:41 -0700)
commit237308a671bd2bbea2059bea9e75cb1272edbdbf
tree031a6383af9d0d6936c5ae85b998194b060a8c0e
parent6445dad7d66fa6a1867090fcd9602c98863649f6
writeDataAtomic() fixes (#140)

* filesystem: ensure data is persisted before returning success

Sync the temporary file before renaming it, to ensure that after a
crash, the destination file isn't zero-length or otherwise incomplete.

Also sync the directory after the rename, to ensure the rename has been
persisted before returning success.

* filesystem: don't use fixed temporary file name

Using a fixed temporary file name in a world-writable sticky directory
is problematic since another user can create the file first.

Use ioutil.TempFile() to do it properly.  It uses O_EXCL under the hood
to ensure the file is newly created.
filesystem/filesystem.go