As a kickoff idea have a look at the Command pattern. This is usually how undo/redo things are implemented. The idea is that you kind of store everything that is "important" about an operation into a single object and you store those in an ordered collection.
In your case the fact that you want to monitor the FS and not your own data model makes things really hard. However if you can afford redundant data storage then hypothetically it can be done I think. (I suggest you reading about the way git SCM works. I mean that it stores everything in a single .git
folder and it is capable of restoring any previous state in its so called working directory from the compressed data it stores.)
Actually if you could involve git into your program then it would be much easier. I am thinking that you have a git repo initialized in the directory that you want to supervise and then every time that you are being notified about some FS change, you can ask git (git status
) to tell you which files got changed actually. Even deleted file can be restored then using simple git commands.
This is far from a complete answer to your question however I might have given some ideas. Good luck.