diff options
author | midipix <writeonce@midipix.org> | 2024-06-06 21:11:11 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2024-06-06 23:39:26 +0000 |
commit | 37f51391c8888c7f84e27ec6995fda5dd3af49c3 (patch) | |
tree | f9c296dc28aaffbb9e2df29c87e86c4b46fef4f8 /src/logic/tpax_archive_enqueue.c | |
parent | b8874b3e640e74ff287b64e969ce74aece65de10 (diff) | |
download | tpax-37f51391c8888c7f84e27ec6995fda5dd3af49c3.tar.bz2 tpax-37f51391c8888c7f84e27ec6995fda5dd3af49c3.tar.xz |
driver: implemented and integrated the -H (follow symlink args) cmdline option.
Diffstat (limited to 'src/logic/tpax_archive_enqueue.c')
-rw-r--r-- | src/logic/tpax_archive_enqueue.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/logic/tpax_archive_enqueue.c b/src/logic/tpax_archive_enqueue.c index 222b0ad..b81661b 100644 --- a/src/logic/tpax_archive_enqueue.c +++ b/src/logic/tpax_archive_enqueue.c @@ -400,6 +400,7 @@ int tpax_archive_enqueue( const struct tpax_unit_ctx * uctx) { int fdat; + int fdlnk; uintptr_t addr; const char * name; const char * mark; @@ -409,11 +410,15 @@ int tpax_archive_enqueue( struct tpax_dirent * cdent; struct tpax_dirent * cnext; struct dirent * dirent; + struct dirent * lnkent; + struct stat lnkst; char entbuf[PATH_MAX + sizeof(struct dirent)]; + char lnkbuf[PATH_MAX + sizeof(struct dirent)]; /* init */ fdat = tpax_driver_fdcwd(dctx); dirent = (struct dirent *)entbuf; + lnkent = (struct dirent *)lnkbuf; prefix = 0; /* split path to prefix + basename */ @@ -449,6 +454,39 @@ int tpax_archive_enqueue( TPAX_NESTED_ERROR(dctx), 0); + /* follow command-line symlink arguments as needed */ + fdlnk = (uctx->link[0] && (dctx->cctx->drvflags & TPAX_DRIVER_PAX_SYMLINK_ARGS)) + ? openat(fdat,uctx->link[0],O_RDONLY|O_CLOEXEC) : (-1); + + if (fdlnk >= 0) { + if (fstat(fdlnk,&lnkst) <0) { + close(fdlnk); + return tpax_archive_enqueue_ret( + TPAX_SYSTEM_ERROR(dctx), + 0); + } + + close(fdlnk); + + if (tpax_dirent_init_from_uctx(&lnkst,uctx->link[0],lnkent) < 0) + return tpax_archive_enqueue_ret( + TPAX_CUSTOM_ERROR( + dctx, + TPAX_ERR_FLOW_ERROR), + 0); + + cdent = tpax_get_driver_dirmark(dctx); + cdent->flags |= TPAX_ITEM_NAMEREF; + + if (tpax_archive_add_queue_item( + dctx,lnkent,cdent,0,1, + TPAX_ITEM_EXPLICIT|TPAX_ITEM_SYMLINK, + fdat,&fkeep) < 0) + return tpax_archive_enqueue_ret( + TPAX_NESTED_ERROR(dctx), + 0); + } + /* queue directory child items */ dentbuf = tpax_get_driver_dirents(dctx); cdent = tpax_get_driver_dirmark(dctx); |