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

查看:114
本文介绍了在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.

这里的关键词是 atomic ...解决方案一定不能以使操作处于不一致状态的任何方式失败.

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天全站免登陆