Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or they use the Windows API well and purposely create new files rather than updating old ones to get atomic updates (the same way that most editors on Unix never ever update existing files and instead create new ones on which they call rename()).


Well they obviously aren't checking for metadata / extended attributes when reading the files.


This issue exists on Linux too :-) ext4 supports extended attributes including the creation time, but most apps blindly rename which means the metadata is lost.


I'm glad someone else said it. I was biting my tongue.


In both operating systems, aren't there APIs for this?


For what? Creatingafilewritingtoitthenrenamingitoveranexistingfile?

Or did you mean moving the metadata as well? Transferring all kinds of metadata from file A to file B is heinously non-portable across OSes and even OS releases. The specific metadata this is about isn't even available in the Win32 API, it's only part of the native API (and the kernel API ofc.)


An API for Atomic operations with files.

There are APIs in windows apparently. A quick Google search reveals function like CreateDirectoryTransacted, and another quick search reveals that the Kernel leaves this kind of thing up to the filesystem. So on Linux filesystems like ZFA and BTRFS just use the normal posix file APIs and others can optionally provide other functions if they choose to.

So yeah... The whole make a file and rename it thing is dirty hack.

EDIT - Grammar


> [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using Transactional NTFS.]


> An API for Atomic operations with files.

Windows has TxF (used in Windows Update and Installer to tame the eeeenormous complexity a tiny bit; TxF and VSS also use similar mechanisms), but no other mainstream OS has anything remotely close.


I don't know how, but I misspelled "ZFS". In ZFS every single file write is atomic. That is kind of close and supported on Linux, Mac OS X and a few Unix flavors.


That kinda doesn't matter with ZFS or btrfs, though; as real CoW file systems their consistency properties are similar to a fully journaled FS (not only metadata but also data, like ext4 in journal=data mode). In that case you don't need to care anymore as an application developer about file committing patterns, as long as it's only about one file.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: