Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is File.Delete() atomic under .NET

Target OS: Win2003

As posted in other SO questions about file operation atomicity, Win32 was simply not designed for transactions. Still I wonder whether file deletion could be non-atomic. After all, it is either get deleted or not. Or can a file remain in any other intermediate state on NTFS file system caused by a system crash or something else during deletion?

like image 487
user256890 Avatar asked Feb 09 '10 15:02

user256890


People also ask

Which method is used to delete a file?

files. deleteifexists(Path p) method defined in Files package: This method deletes a file if it exists. It also deletes a directory mentioned in the path only if the directory is empty.

How do I delete a file in Java NIO?

In Java, we can use the NIO Files. delete(Path) and Files. deleteIfExists(Path) to delete a file.

Can Javascript delete files?

You can't delete a file when running JavaScript from the browser, but you can do it when running JavaScript from a server environment like NodeJS. When you need to delete a file using NodeJS, You can use the fs. unlink() or fs. unlinkSync() method.


1 Answers

NTFS is a journaled file system. A journal is basically equivalent to a transaction log in a database. It'll ensure consistency and integrity of the file system structures like a database does for its tables. While File.Delete doesn't have any transactional code at the high level, NTFS does maintain transactional integrity at the filesystem level. This may not be true for other file system drivers.

like image 176
mmx Avatar answered Nov 22 '22 14:11

mmx