Page 1 of 1

File based "transactions"

Posted: Thu Jan 15, 2009 2:49 pm
by kaisellgren
Hello,

Just like SQL transactions, but in file based level. I have a pack of content that should be written into multiple different files, if any of them fail (the md5 doesn't match), then rollback all files to previous state.

The only reasonable way of accomplishing this seems to be looping through the content and check the md5's of the files and if any md5 match fails during loop then cancel whole operation otherwise loop through them again and this time make the actual changes to the files not just reading the content and comparing md5s.

Re: File based "transactions"

Posted: Thu Jan 15, 2009 3:13 pm
by alex.barylski
If it's mission critical, do whatever it takes to use a transaction supported database.

Otherwise, your algorithm sounds about right, yes.

Save the MD5/CRC32 of the original files. Copy them into place or upload, whatever, then check each file CRC32 and compare that against the newly updated/uploaded files. On failure, restore the temp buffered files to their original glory.

Re: File based "transactions"

Posted: Thu Jan 15, 2009 3:16 pm
by requinix
How about making a temporary copy of the file(s) to be modified?
Make your changes, check that everything worked, and then copy the temporary back over the original.