summaryrefslogtreecommitdiff
path: root/src/logic
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2021-10-23 18:19:08 +0000
committermidipix <writeonce@midipix.org>2024-05-19 03:36:18 +0000
commit9f55a17009446a7586a3694edb0b54988e201e7f (patch)
tree6127167b34a675b3482d9c918d213527bb879cb7 /src/logic
parent3179bb713afab5e24853313e36d5fde9b2295238 (diff)
downloadtpax-9f55a17009446a7586a3694edb0b54988e201e7f.tar.bz2
tpax-9f55a17009446a7586a3694edb0b54988e201e7f.tar.xz
item queue: implemented tpax_append_prefix_item().
Diffstat (limited to 'src/logic')
-rw-r--r--src/logic/tpax_archive_append.c55
1 files changed, 53 insertions, 2 deletions
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);