views:

109

answers:

1

Hi,

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?

+2  A: 

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.

TomTom