在 Windows 上可以重命名(覆盖)原子文件吗? [英] Is an atomic file rename (with overwrite) possible on Windows?

查看:20
本文介绍了在 Windows 上可以重命名(覆盖)原子文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 POSIX 系统上,rename(2) 提供原子重命名操作,包括覆盖目标文件(如果存在且权限允许).

On POSIX systems rename(2) provides for an atomic rename operation, including overwriting of the destination file if it exists and if permissions allow.

有没有办法在 Windows 上获得相同的语义?我知道 Vista 和 Server 2008 上的 MoveFileTransacted(),但我需要它来支持 Win2k 及更高版本.

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.

我看到很多人说这在 win32 上是不可能的,但我问你,真的吗?

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

您将不得不编写自己的例程来支持这一点.很遗憾,但您不能指望 win32 提供这种级别的服务 - 它根本不是为此而设计的.

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.

这篇关于在 Windows 上可以重命名(覆盖)原子文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆