This patch adds the ability to safely cancel the verification or repair process.
I use libpar2 in project nzbget (nzbget.sourceforge.net). It's a download daemon, widely used on devices with very slow CPUs, like NAS and routers. On such devices the repair process easily may take few hours, in extreme cases even days.
I needed the ability to cancel repair without termination of my program.
The patch introduces new protected field "cancelled" in class Par2Repairer (par2repairer.cpp). The implementation of this class was extended to check the variable after each iteration during verification and repair. If it is set the job interrupts. The patch ensures that all allocated objects are freed.
Descendants of Par2Repairer can set field "cancelled" to stop the verification or repair. The best place to set the state is in the handler of progress event (sig_progress). If needed the descendants of Par2Repairer may provide a public access to field "cancelled" for other classes.
1) If the process was cancelled the return status of functions "PreProcess" and "Process" is undefined. They may return eRepairFailed, eFileIOError, etc. I didn't extend the "enum Result" with new code such as "eRepairCancelled" to not break compatibility with existing code which uses libpar2.
The implementation which uses the cancellation feature, must check the field "cancelled" after the calling of functions "PreProcess" and "Process" before checking the returned value of these functions.
2) If the process was cancelled no cleanup on disk is being made. The partially constructed files remain on disk as well as original files remain renamed to "*.1". The caller may do cleanup on its own, if required.
Log in to post a comment.