在POSIX系统上,重命名(2)提供原子重命名操作,包括覆盖目标文件(如果存在)以及权限允许的话。
有没有办法在Windows上获得相同的语义? 我知道Vista和Server 2008上的MoveFileTransacted(),但是我需要这个来支持Win2k和更高版本。
这里的关键词是原子 ...解决方案不能以任何使操作处于不一致状态的方式失败。
我看到很多人说这是不可能的win32,但我问你,真的吗?
请尽可能提供可靠的引文。
On POSIX systems rename(2) provides for an atomic rename operation, including overwriting of the destination file if it exists and if permissions allow.
Is there any way to get the same semantics on Windows? I know about MoveFileTransacted() on Vista and Server 2008, but I need this to support Win2k and up.
The key word here is atomic... the solution must not be able to fail in any way that leaves the operation in an inconsistent state.
I've seen a lot of people say this is impossible on win32, but I ask you, is it really?
Please provide reliable citations if possible.
最满意答案
Win32不保证原子文件元数据操作。 我会提供一个引文,但没有一个 - 事实上没有书面或文件化的保证手段。
你将不得不编写自己的例程来支持这一点。 这是不幸的,但你不能指望win32提供这种服务水平 - 它根本不是为它设计的。
-亚当
Win32 does not guarantee atomic file meta data operations. I'd provide a citation, but there is none - that fact that there's no written or documented guarantee means as much.
You're going to have to write your own routines to support this. It's unfortunate, but you can't expect win32 to provide this level of service - it simply wasn't designed for it.
更多推荐
发布评论