Note: ca is used (and required) iff the entry refers to a regular file. */
| 281 | |
| 282 | /* Note: ca is used (and required) iff the entry refers to a regular file. */ |
| 283 | static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca, |
| 284 | const struct checkout *state, int to_tempfile, |
| 285 | int *nr_checkouts) |
| 286 | { |
| 287 | unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT; |
| 288 | struct delayed_checkout *dco = state->delayed_checkout; |
| 289 | int fd, ret, fstat_done = 0; |
| 290 | char *new_blob; |
| 291 | struct strbuf buf = STRBUF_INIT; |
| 292 | size_t size; |
| 293 | ssize_t wrote; |
| 294 | size_t newsize = 0; |
| 295 | struct stat st; |
| 296 | const struct submodule *sub; |
| 297 | struct checkout_metadata meta; |
| 298 | static int scratch_nr_checkouts; |
| 299 | |
| 300 | clone_checkout_metadata(&meta, &state->meta, &ce->oid); |
| 301 | |
| 302 | if (ce_mode_s_ifmt == S_IFREG) { |
| 303 | struct stream_filter *filter = get_stream_filter_ca(ca, &ce->oid); |
| 304 | if (filter && |
| 305 | !streaming_write_entry(ce, path, filter, |
| 306 | state, to_tempfile, |
| 307 | &fstat_done, &st)) |
| 308 | goto finish; |
| 309 | } |
| 310 | |
| 311 | switch (ce_mode_s_ifmt) { |
| 312 | case S_IFLNK: |
| 313 | new_blob = read_blob_entry(ce, &size); |
| 314 | if (!new_blob) |
| 315 | return error("unable to read sha1 file of %s (%s)", |
| 316 | ce->name, oid_to_hex(&ce->oid)); |
| 317 | |
| 318 | /* |
| 319 | * We can't make a real symlink; write out a regular file entry |
| 320 | * with the symlink destination as its contents. |
| 321 | */ |
| 322 | if (!has_symlinks || to_tempfile) |
| 323 | goto write_file_entry; |
| 324 | |
| 325 | ret = symlink(new_blob, path); |
| 326 | free(new_blob); |
| 327 | if (ret) |
| 328 | return error_errno("unable to create symlink %s", path); |
| 329 | break; |
| 330 | |
| 331 | case S_IFREG: |
| 332 | /* |
| 333 | * We do not send the blob in case of a retry, so do not |
| 334 | * bother reading it at all. |
| 335 | */ |
| 336 | if (dco && dco->state == CE_RETRY) { |
| 337 | new_blob = NULL; |
| 338 | size = 0; |
| 339 | } else { |
| 340 | new_blob = read_blob_entry(ce, &size); |
no test coverage detected