Is an atomic-rename possible in Mac VFS/HFS+?

限于喜欢 提交于 2020-01-11 13:25:14

问题


With support for ACLs in Mac OS X, there is a way to declare a file as writeable but non-deletable.

This poses a problem with atomic writes, since the current implementation of rename in VFS deletes a pre-existing target. If you have an existing file, which you have write privileges on, it is possible to be unable to atomically write to:
Simply attach an ACL that states deny delete and an atomic write (like implemented by various Cocoa APIs — e.g. NSArray's writeToFile:atomically:) will fail, while a non-atomic write will happily succeed.

Since my understanding of low-level C code is fairly limited:
Is an alternative implementation feasible with only minor (insert your favorite definition of "minor") headaches?

Thanks

Daniel


回答1:


A viable alternative would seem to create the file in a temporary directory, then call exchangedata on both files. HFS exports the VOL_CAP_INT_EXCHANGEDATA attribute, so that should work. The relevant checks in vfs_syscalls.c indicate that only read and write permissions are necessary for the call to succeed.



来源:https://stackoverflow.com/questions/4662115/is-an-atomic-rename-possible-in-mac-vfs-hfs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!