Something like this?
- Create a transaction ID, $id. Just use $$ and check for collisions (or hope for no collisions).
- 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).
- 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".
- Wait for a commit request
- For each file that was moved:
- Append a line to the transaction journal saying you are about to rename the file
- Rename the source file to ".$id.$origFileName"
- Append a line to the journal saying you have finished renaming the file
- For each destination file:
- Append a line to the journal saying you are about to rename the file
- Rename the file to $desiredFinalName
- Append a line to the journal saying you finished renaming
- Remove the journal for the successfully committed transaction
if something fails then you use the journal to rollback.
-
tye