| 3228 | } |
| 3229 | |
| 3230 | static int apply_binary_fragment(struct apply_state *state, |
| 3231 | struct image *img, |
| 3232 | struct patch *patch) |
| 3233 | { |
| 3234 | struct fragment *fragment = patch->fragments; |
| 3235 | size_t len; |
| 3236 | void *dst; |
| 3237 | |
| 3238 | if (!fragment) |
| 3239 | return error(_("missing binary patch data for '%s'"), |
| 3240 | patch->new_name ? |
| 3241 | patch->new_name : |
| 3242 | patch->old_name); |
| 3243 | |
| 3244 | /* Binary patch is irreversible without the optional second hunk */ |
| 3245 | if (state->apply_in_reverse) { |
| 3246 | if (!fragment->next) |
| 3247 | return error(_("cannot reverse-apply a binary patch " |
| 3248 | "without the reverse hunk to '%s'"), |
| 3249 | patch->new_name |
| 3250 | ? patch->new_name : patch->old_name); |
| 3251 | fragment = fragment->next; |
| 3252 | } |
| 3253 | switch (fragment->binary_patch_method) { |
| 3254 | case BINARY_DELTA_DEFLATED: |
| 3255 | dst = patch_delta(img->buf.buf, img->buf.len, fragment->patch, |
| 3256 | fragment->size, &len); |
| 3257 | if (!dst) |
| 3258 | return -1; |
| 3259 | image_clear(img); |
| 3260 | strbuf_attach(&img->buf, dst, len, len + 1); |
| 3261 | return 0; |
| 3262 | case BINARY_LITERAL_DEFLATED: |
| 3263 | image_clear(img); |
| 3264 | strbuf_add(&img->buf, fragment->patch, fragment->size); |
| 3265 | return 0; |
| 3266 | } |
| 3267 | return -1; |
| 3268 | } |
| 3269 | |
| 3270 | /* |
| 3271 | * Replace "img" with the result of applying the binary patch. |
no test coverage detected