Something like this?

  1. Create a transaction ID, $id. Just use $$ and check for collisions (or hope for no collisions).
  2. Write a transaction journal file (probably just use a good temp-file module) that contains source and destination pairs (and whether it is a move or copy, if you want to support both).
  3. Copy all of the files to the destination file system with names something like ".$id.$desiredFinalName", checking for collisions so you can abort the "transaction".
  4. Wait for a commit request
  5. For each file that was moved:
    1. Append a line to the transaction journal saying you are about to rename the file
    2. Rename the source file to ".$id.$origFileName"
    3. Append a line to the journal saying you have finished renaming the file
  6. For each destination file:
    1. Append a line to the journal saying you are about to rename the file
    2. Rename the file to $desiredFinalName
    3. Append a line to the journal saying you finished renaming
  7. Remove the journal for the successfully committed transaction
if something fails then you use the journal to rollback.

                - tye

In reply to Re: Move files w/ commit-rollback mechanism? (journaled move) by tye
in thread Move files w/ commit-rollback mechanism? by chunlou

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.