From 239ac5c3f246a737d7b70817319a37d6cece8a69 Mon Sep 17 00:00:00 2001 From: midipix Date: May 23 2020 05:59:02 +0000 Subject: driver: tpax_get_unit_ctx(): implemented the non-recursive bits. --- diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h index 8c45468..a06a1e5 100644 --- a/include/tpax/tpax.h +++ b/include/tpax/tpax.h @@ -119,6 +119,10 @@ struct tpax_driver_ctx { struct tpax_unit_ctx { const char * const * path; + const char * const * link; + const struct tpax_ustar_header *uhdr; + const struct tpax_cpio_header * chdr; + const struct stat * st; void * any; }; diff --git a/src/driver/tpax_unit_ctx.c b/src/driver/tpax_unit_ctx.c index a6a91b6..a94bf05 100644 --- a/src/driver/tpax_unit_ctx.c +++ b/src/driver/tpax_unit_ctx.c @@ -8,11 +8,13 @@ #include #include #include -#include +#include +#include #include #include "tpax_driver_impl.h" #include "tpax_errinfo_impl.h" +#include "tpax_readlink_impl.h" static int tpax_free_unit_ctx_impl(struct tpax_unit_ctx_impl * ctx, int ret) { @@ -28,6 +30,7 @@ int tpax_get_unit_ctx( const char * path, struct tpax_unit_ctx ** pctx) { + int ret; struct tpax_unit_ctx_impl * ctx; if (!dctx) @@ -40,8 +43,32 @@ int tpax_get_unit_ctx( tpax_driver_set_ectx( dctx,0,path); + if (dctx->cctx->drvflags & TPAX_DRIVER_EXEC_MODE_WRITE_COPY) { + ret = fstatat( + tpax_driver_fdcwd(dctx),path, + &ctx->st,AT_SYMLINK_NOFOLLOW); + + if (ret < 0) { + free(ctx); + return TPAX_SYSTEM_ERROR(dctx); + } + } + + if (S_ISLNK(ctx->st.st_mode)) { + if (tpax_readlink( + path,ctx->linkbuf, + sizeof(ctx->linkbuf)) < 0) { + free(ctx); + return TPAX_SYSTEM_ERROR(dctx); + } + } + ctx->path = path; + ctx->link = ctx->linkbuf; + ctx->uctx.path = &ctx->path; + ctx->uctx.link = &ctx->link; + ctx->uctx.st = &ctx->st; *pctx = &ctx->uctx; diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h index 74af288..5f98415 100644 --- a/src/internal/tpax_driver_impl.h +++ b/src/internal/tpax_driver_impl.h @@ -9,14 +9,20 @@ #include #include +#include #include #include +#include #include "tpax_dprintf_impl.h" #include "argv/argv.h" #define TPAX_OPTV_ELEMENTS 64 +#define TPAX_DRIVER_EXEC_MODE_WRITE_COPY \ + (TPAX_DRIVER_EXEC_MODE_WRITE | \ + TPAX_DRIVER_EXEC_MODE_COPY) + extern const struct argv_option tpax_default_options[]; enum app_tags { @@ -47,6 +53,13 @@ struct tpax_driver_ctx_impl { struct tpax_unit_ctx_impl { const char * path; struct tpax_unit_ctx uctx; + struct stat st; + const char * link; + char linkbuf[1024]; + union { + struct tpax_ustar_header uhdr; + struct tpax_cpio_header chdr; + } hdrbufs; };