File.Move的原子原子、File、Move

由网友(秃头仙女)分享简介:我要重命名的目录中的文件作为一个原子事务。该文件将不会被更改目录。路径是作为一个UNC路径到一个NTFS文件系统,可能是任一服务器03或08上。I want to rename a file in a directory as an atomic transaction. The file will not be c...

我要重命名的目录中的文件作为一个原子事务。该文件将不会被更改目录。路径是作为一个UNC路径到一个NTFS文件系统,可能是任一服务器03或08上。

I want to rename a file in a directory as an atomic transaction. The file will not be changing directories. The path is provided as a UNC Path to an NTFS file system, probably on either Server 03 or 08.

时File.Move()的原子为这些目的?如,它要么成功完成或失败,使得原来的文件仍然完好?

Is File.Move() atomic for these purposes? As in, it either completes successfully or fails such that the original file is still intact?

我的直觉说,是的,但我想确认一下。

My gut says yes, but I wanted to make sure.

推荐答案

是的,在NTFS。从here:

Yes, in NTFS. From here:

顺便说一句,如果你是NTFS下运行,那么文件操作都是原子在文件系统级别。会出现一个重命名在一个操作就任何更高的code而言。您所看到的问题几乎似乎是其中的FileInfo对象被在应用程序之间共享的问题。它是一个MarshalByRef对象,因此可以在远程环境中使用。不知道这是否适用于你。

As an aside if you are running under NTFS then file operations are atomic at the file system level. A rename will occur in a single operation as far as any higher code is concerned. The problem you are seeing almost appears to be an issue where the FileInfo object is being shared across applications. It is a MarshalByRef object and therefore can be used in remoting environments. Don't know if this applies to you.

阅读全文

相关推荐

最新文章