Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any sort of File system transaction mechanism available to .net application?

I'm implementing a simple update mechanism for an application I'm writing the last part of the update process consist in renaming the current application executable file from something like myApp.exe to myApp.old.exe and then renaming the freshly downloaded and updated file from myApp.new.exe to myApp.exe.

I'd like to find a way for theses two operation to be atomic, because if my application crash (for any reason, like an asteroids falling on a power line) after it renamed itself and before it renamed the new version, it will be stuck in a state where it can't be restarted by using the usual shortcuts, so it won't be able to finish it's update.

So is there anyway to make the update failsafe?

like image 667
Mathieu Pagé Avatar asked Nov 06 '22 15:11

Mathieu Pagé


1 Answers

On 2008/Vista upward yes, though it is not exposed. At that point, NTFS got file system transactions on the file system / kernel level.

Please check:

http://www.michaelckennedy.net/blog/2007/12/07/SystemTransactionsAndWindowsVistaNTFSUpdated.aspx

http://www.codeguru.com/cpp/misc/misc/fileio/article.php/c9987

http://xavierdecoster.wordpress.com/2009/10/18/transactional-ntfs-txf/

They have code samples.

like image 170
TomTom Avatar answered Nov 15 '22 02:11

TomTom