Windows上是否可以重命名(覆盖)原子文件?(Is an atomic file rename (with overwrite) possible on Windows?)

编程入门 行业动态 更新时间:2024-10-27 16:23:26
Windows上是否可以重命名(覆盖)原子文件?(Is an atomic file rename (with overwrite) possible on Windows?)

在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.

更多推荐

本文发布于:2023-07-14 17:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原子   重命名   文件   Windows   overwrite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!