From 9f55a17009446a7586a3694edb0b54988e201e7f Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 23 Oct 2021 18:19:08 +0000 Subject: item queue: implemented tpax_append_prefix_item(). --- src/logic/tpax_archive_append.c | 55 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'src/logic') diff --git a/src/logic/tpax_archive_append.c b/src/logic/tpax_archive_append.c index 4bc3d2f..d8ac12f 100644 --- a/src/logic/tpax_archive_append.c +++ b/src/logic/tpax_archive_append.c @@ -49,6 +49,49 @@ static int tpax_archive_append_memory_data( return 0; } +static char * tpax_append_prefix_item( + const struct tpax_driver_ctx * dctx, + const char * prefix) +{ + struct tpax_driver_ctx_impl * ictx; + char ** prefv; + char ** psrc; + char ** pdst; + off_t elements; + char * pitem; + + ictx = tpax_get_driver_ictx(dctx); + + for (psrc=ictx->prefixv; *psrc; psrc++) + if (!strcmp(*psrc,prefix)) + return *psrc; + + if (ictx->prefixp == ictx->prefcap) { + elements = ictx->prefcap - ictx->prefixv; + elements += 256; + + if (!(prefv = calloc(elements,sizeof(char *)))) + return 0; + + for (psrc=ictx->prefixv,pdst=prefv; *psrc; psrc++,pdst++) + *pdst = *psrc; + + if (ictx->prefixv != ictx->prefptr) + free(ictx->prefixv); + + ictx->prefixv = prefv; + ictx->prefixp = pdst; + ictx->prefcap = &prefv[--elements]; + } + + if (!(pitem = strdup(prefix))) + return 0; + + *ictx->prefixp++ = pitem; + + return pitem; +} + static int tpax_archive_append_pad( const struct tpax_driver_ctx * dctx, int fdout, @@ -144,11 +187,12 @@ static int tpax_archive_append_queue_item( const struct tpax_driver_ctx * dctx, const struct dirent * dirent, const struct tpax_dirent * parent, + const char * prefix, struct tpax_unit_ctx * unit, int depth, + int flags, int fd, bool * fkeep) - { struct tpax_dirent_buffer * dentbuf; struct tpax_dirent * cdent; @@ -183,8 +227,10 @@ static int tpax_archive_append_queue_item( cdent->fdat = fd; cdent->depth = depth; + cdent->flags = flags; cdent->nsize = needed; cdent->parent = parent; + cdent->prefix = prefix; memset(&cdent->dirent,0,offsetof(struct dirent,d_name)); @@ -510,7 +556,8 @@ static int tpax_archive_append_dir( if (dirent->d_type == DT_DIR) { if (tpax_archive_append_queue_item( dctx,dirent, - parent,unit,depth, + parent,0,unit,depth, + TPAX_ITEM_IMPLICIT, fd,&fkeep) < 0) return tpax_archive_append_ret( TPAX_NESTED_ERROR(dctx), @@ -598,6 +645,10 @@ int tpax_archive_append( for (++prefix; *prefix=='/'; prefix++) (void)0; + if (prefix) + if (!(prefix = tpax_append_prefix_item(dctx,prefix))) + return TPAX_BUFFER_ERROR(dctx); + /* append explicit item */ tpax_archive_append_impl(dctx,uctx,0,prefix,0); -- cgit v1.2.3