WebAssembly / wasi-filesystem

Filesystem API for WASI
175 stars 18 forks source link

fsync on directories on Windows #79

Open sunfishcode opened 1 year ago

sunfishcode commented 1 year ago

In POSIX circles, which WASI generally tries to follow, there are some use cases for fsyncing a directory, to ensure that a file's directory entry has been written to storage.

However, on Windows, there's FlushFileBuffers for syncing files to storage, but it only works on files. There doesn't appear to be a way to do this for directories. There is some discussion in the FlushFileBuffers documentation about optimizing buffering, but I don't see any documentation about syncing directory entries.

Should Windows implementations of the sync function just silently succeed, indicating that the implementation did the best it could? Or should it unconditionally fail to signal that nothing could be done?

sunfishcode commented 1 year ago

For completeness, it's also possible to call FlushFileBuffers on a volume handle, however that requires administrator access.

Another datapoint here is that on Linux, an O_PATH file descriptor, which is otherwise sufficient to implement a directory handle for WASI's purposes, does not support fsync.

I'm considering saying that we should not support fsync on directories in WASI, and that we should instead introduce separate APIs for implementing atomic file operations which allow platforms that can do fsync on directories do so but also let other platforms use OS features that work differently.