summaryrefslogtreecommitdiffhomepage
path: root/src/logic
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-07-13 05:03:48 +0000
committermidipix <writeonce@midipix.org>2024-07-14 20:18:46 +0000
commit5ea1d7cd4b630a91b4a72fb722a937a107d76fc0 (patch)
tree034f126157e388b09a615989d959d6ac39402824 /src/logic
parentc1438ffaef9c2f9ae116ebc375db2cc1468c341c (diff)
downloadtpax-5ea1d7cd4b630a91b4a72fb722a937a107d76fc0.tar.bz2
tpax-5ea1d7cd4b630a91b4a72fb722a937a107d76fc0.tar.xz
driver: -s <replstr> support: implementation and integration.
Diffstat (limited to 'src/logic')
-rw-r--r--src/logic/tpax_archive_write.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/logic/tpax_archive_write.c b/src/logic/tpax_archive_write.c
index 32a5f2c..a881bd9 100644
--- a/src/logic/tpax_archive_write.c
+++ b/src/logic/tpax_archive_write.c
@@ -75,6 +75,35 @@ static int tpax_archive_write_ret(
return ret;
}
+static int tpax_apply_string_replacement(
+ const struct tpax_driver_ctx * dctx,
+ const char * path,
+ char * replbuf,
+ size_t buflen)
+{
+ int ret;
+ struct tpax_driver_ctx_impl * ictx;
+ struct tpax_replstr * replstrv;
+
+ ictx = tpax_get_driver_ictx(dctx);
+
+ if (!(replstrv = ictx->replstrv))
+ return 0;
+
+ for (ret=0; !ret && replstrv->regexp; replstrv++) {
+ ret = tpax_util_path_replstr(
+ replbuf,path,
+ replstrv->replstr,
+ &replstrv->regex,
+ buflen,replstrv->flags);
+
+ if ((ret > 0) && (replstrv->flags & TPAX_REPL_PRINT))
+ tpax_dprintf(tpax_driver_fderr(dctx),"%s >> %s\n",path,replbuf);
+ }
+
+ return ret;
+}
+
static int tpax_archive_write_impl(
const struct tpax_driver_ctx * dctx,
const struct tpax_dirent * cdent,
@@ -85,12 +114,14 @@ static int tpax_archive_write_impl(
struct tpax_ustar_header uhdr;
const struct stat * st;
struct stat stbuf;
+ const char * apath;
const char * path;
const char * slnk;
const char * mlnk;
off_t hpos;
off_t dpos;
int fdtmp;
+ int slen;
ssize_t nread;
ssize_t nbytes;
void * buf;
@@ -98,6 +129,7 @@ static int tpax_archive_write_impl(
size_t cmplen;
void * membuf;
char * ch;
+ char replbuf[PATH_MAX];
char pathbuf[PATH_MAX];
/* followed symlink? */
@@ -110,9 +142,17 @@ static int tpax_archive_write_impl(
dctx,
TPAX_ERR_FLOW_ERROR);
+ /* regex matching and patter substitution */
+ if ((slen = tpax_apply_string_replacement(dctx,path,replbuf,PATH_MAX)) < 0)
+ return TPAX_CUSTOM_ERROR(
+ dctx,
+ TPAX_ERR_FLOW_ERROR);
+
+ apath = slen ? replbuf : path;
+
/* verbose mode */
if (dctx->cctx->drvflags & TPAX_DRIVER_VERBOSE)
- tpax_dprintf(tpax_driver_fderr(dctx),"%s",path);
+ tpax_dprintf(tpax_driver_fderr(dctx),"%s",apath);
/* uctx */
if (tpax_lib_get_unit_ctx(dctx,fdcwd,path,&uctx) < 0)
@@ -171,7 +211,7 @@ static int tpax_archive_write_impl(
/* header */
if (tpax_meta_init_ustar_header(
- dctx,path,st,
+ dctx,apath,st,
slnk,&uhdr) < 0)
return tpax_archive_write_ret(
TPAX_NESTED_ERROR(dctx),