#16 [libpar2] Safe cancelling of verification/repair

open
nobody
None
5
2008-10-30
2008-10-30
Andrey Prygunkov
No

This patch adds the ability to safely cancel the verification or repair process.

Purpose:
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.

Patch:
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.

Usage:
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.

Notes:
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.

Discussion

  • Added support for cancelling of verification or repair process