diff options
author | midipix <writeonce@midipix.org> | 2024-06-06 05:35:30 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2024-06-06 21:44:32 +0000 |
commit | b8874b3e640e74ff287b64e969ce74aece65de10 (patch) | |
tree | 028505c1b32f289adbf0fd3e0759bb634a417388 /src/logic | |
parent | 594da7961c69eb573a1bef26578a6ec536511535 (diff) | |
download | tpax-b8874b3e640e74ff287b64e969ce74aece65de10.tar.bz2 tpax-b8874b3e640e74ff287b64e969ce74aece65de10.tar.xz |
tpax_archive_write_impl(): refactor references to stat info and symlink target.
Diffstat (limited to 'src/logic')
-rw-r--r-- | src/logic/tpax_archive_write.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/logic/tpax_archive_write.c b/src/logic/tpax_archive_write.c index 2555d26..1a641bf 100644 --- a/src/logic/tpax_archive_write.c +++ b/src/logic/tpax_archive_write.c @@ -79,7 +79,9 @@ static int tpax_archive_write_impl( { struct tpax_unit_ctx * uctx; struct tpax_ustar_header uhdr; + const struct stat * st; const char * path; + const char * slnk; off_t hpos; off_t dpos; int fdtmp; @@ -100,6 +102,9 @@ static int tpax_archive_write_impl( if (tpax_lib_get_unit_ctx(dctx,fdcwd,path,&uctx) < 0) return TPAX_NESTED_ERROR(dctx); + st = uctx->st; + slnk = uctx->link[0]; + /* record errors */ tpax_driver_set_ectx( dctx,0,path); @@ -110,8 +115,8 @@ static int tpax_archive_write_impl( /* header */ if (tpax_meta_init_ustar_header( - dctx,path,uctx->st, - *uctx->link,&uhdr) < 0) + dctx,path,st, + slnk,&uhdr) < 0) return tpax_archive_write_ret( TPAX_NESTED_ERROR(dctx), uctx); @@ -121,25 +126,25 @@ static int tpax_archive_write_impl( fdtmp = -1; /* associated data? */ - if S_ISREG(uctx->st->st_mode) { + if S_ISREG(st->st_mode) { buf = tpax_get_driver_anon_map_addr( dctx,&buflen); - if (buflen >= (cmplen = uctx->st->st_size)) + if (buflen >= (cmplen = st->st_size)) membuf = buf; /* snapshot */ if (membuf) { if (tpax_io_create_memory_snapshot( dctx,fdcwd,path, - uctx->st,membuf) < 0) + st,membuf) < 0) return tpax_archive_write_ret( TPAX_NESTED_ERROR(dctx), uctx); } else { if ((fdtmp = tpax_io_create_tmpfs_snapshot( dctx,fdcwd,path, - uctx->st)) < 0) + st)) < 0) return tpax_archive_write_ret( TPAX_NESTED_ERROR(dctx), uctx); @@ -164,7 +169,7 @@ static int tpax_archive_write_impl( tpax_set_driver_cpos(dctx,dpos); /* all done? */ - if (!(S_ISREG(uctx->st->st_mode))) { + if (!(S_ISREG(st->st_mode))) { tpax_lib_free_unit_ctx(uctx); return 0; } @@ -174,7 +179,7 @@ static int tpax_archive_write_impl( buf = tpax_get_driver_anon_map_addr( dctx,&buflen); - for (nread=0; nread<uctx->st->st_size; ) { + for (nread=0; nread<st->st_size; ) { nbytes = read(fdtmp,buf,buflen); while ((nbytes < 0) && (errno == EINTR)) @@ -208,14 +213,14 @@ static int tpax_archive_write_impl( } else { if (tpax_archive_append_memory_data( fdout,membuf, - uctx->st->st_size) < 0) + st->st_size) < 0) return tpax_archive_write_ret( TPAX_SYSTEM_ERROR(dctx), uctx); } return tpax_archive_write_ret( - tpax_archive_append_pad(dctx,fdout,uctx->st), + tpax_archive_append_pad(dctx,fdout,st), uctx); } |