The private writer is closed before spawn. Only canonical OID lines reach * this transport; the child opens its independent read-only binary handle. */
| 352 | /* The private writer is closed before spawn. Only canonical OID lines reach |
| 353 | * this transport; the child opens its independent read-only binary handle. */ |
| 354 | static bool gf_capture_input(cbm_git_facts_t *facts, gf_capture_t *capture, |
| 355 | const cbm_git_bytes_t *input, cbm_git_facts_error_t *error) { |
| 356 | if (!input) |
| 357 | return true; |
| 358 | gf_batch_budget_t *budget = facts->batch_budget; |
| 359 | if (!budget || (input->length && !input->data)) |
| 360 | return gf_error(error, CBM_GIT_FACTS_INVALID, "Invalid internal Git batch input"); |
| 361 | if (!gf_gate(facts, error)) |
| 362 | return false; |
| 363 | if (input->length > budget->input_limit - budget->input_used) |
| 364 | return gf_limit(facts, error, "Git batch stdin limit exceeded"); |
| 365 | int n = snprintf(capture->in, sizeof(capture->in), "%s/stdin", capture->directory); |
| 366 | if (n < 0 || (size_t)n >= sizeof(capture->in)) { |
| 367 | capture->in[0] = '\0'; |
| 368 | return gf_error(error, CBM_GIT_FACTS_IO, "Batch input path exceeds supported length"); |
| 369 | } |
| 370 | FILE *file = cbm_fopen(capture->in, "wb"); |
| 371 | if (!file) |
| 372 | return gf_error(error, CBM_GIT_FACTS_IO, "Cannot create private Git batch input"); |
| 373 | bool ok = true; |
| 374 | size_t at = 0; |
| 375 | while (at < input->length) { |
| 376 | if (!gf_gate(facts, error)) { |
| 377 | ok = false; |
| 378 | break; |
| 379 | } |
| 380 | size_t chunk = input->length - at; |
| 381 | if (chunk > 65536) |
| 382 | chunk = 65536; |
| 383 | size_t written = fwrite(input->data + at, 1, chunk, file); |
| 384 | at += written; |
| 385 | budget->input_used += written; |
| 386 | if (written != chunk) { |
| 387 | ok = gf_error(error, CBM_GIT_FACTS_IO, "Cannot write private Git batch input"); |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | if (fclose(file) != 0 && ok) |
| 392 | ok = gf_error(error, CBM_GIT_FACTS_IO, "Cannot close private Git batch input"); |
| 393 | return ok && gf_gate(facts, error); |
| 394 | } |
| 395 | |
| 396 | static bool gf_capture_sizes(cbm_git_facts_t *facts, const gf_capture_t *capture, size_t *out_size, |
| 397 | size_t *err_size, cbm_git_facts_error_t *error) { |