refactor libpatch interface