A piece of python's code is writing/creating multiple files. I would like to put it in a transaction-ish way, so everything is rolled-back if one of the file's creation fails. This would help to save hard-drive space and avoid unuseful files from failed transactions.
Concretely, by sending a picture to my python server:
- It first saves the original file, full res
- Creates a smaller version of the pic
- Saves this smaller verion
- Transaction succeded
However step 2 or 3 could fail for some reason. How to rollback step 1 ?
The solution should be generic as there might be more steps.
Is there a common transaction trick in Python ?