summaryrefslogtreecommitdiff
path: root/src/logic
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-05-18 02:32:12 +0000
committermidipix <writeonce@midipix.org>2024-05-19 03:36:18 +0000
commitafec656496cbc52e0a31cd016706f035ff2cada5 (patch)
tree234e8e77c9cfe4cad6e4689152e3d642431940c0 /src/logic
parentf5ae320ff28a77cb8bfe21a24369500f86c19df1 (diff)
downloadtpax-afec656496cbc52e0a31cd016706f035ff2cada5.tar.bz2
tpax-afec656496cbc52e0a31cd016706f035ff2cada5.tar.xz
item queue: refactored tpax_archive_append_dir_entries().
Diffstat (limited to 'src/logic')
-rw-r--r--src/logic/tpax_archive_append.c86
1 files changed, 33 insertions, 53 deletions
diff --git a/src/logic/tpax_archive_append.c b/src/logic/tpax_archive_append.c
index 1ff71bc..f467c4a 100644
--- a/src/logic/tpax_archive_append.c
+++ b/src/logic/tpax_archive_append.c
@@ -188,7 +188,6 @@ static int tpax_archive_append_queue_item(
const struct dirent * dirent,
const struct tpax_dirent * parent,
const char * prefix,
- struct tpax_unit_ctx * unit,
int depth,
int flags,
int fd,
@@ -205,7 +204,7 @@ static int tpax_archive_append_queue_item(
if (!(dentbuf = tpax_dirent_buf_first_alloc(dctx)))
return tpax_archive_append_ret(
TPAX_SYSTEM_ERROR(dctx),
- unit);
+ 0);
needed = dirent->d_reclen;
needed += offsetof(struct tpax_dirent,dirent);
@@ -220,7 +219,7 @@ static int tpax_archive_append_queue_item(
if (!(dentbuf = tpax_dirent_buf_next_alloc(dentbuf)))
return tpax_archive_append_ret(
TPAX_SYSTEM_ERROR(dctx),
- unit);
+ 0);
*fkeep = true;
cdent = dentbuf->cdent;
@@ -467,48 +466,37 @@ static int tpax_archive_append_one(
unit);
}
-static int tpax_archive_append_dir(
+static int tpax_archive_append_dir_entries(
const struct tpax_driver_ctx * dctx,
- const struct tpax_unit_ctx * uctx,
- struct tpax_dirent * dent,
- int fdat,
- int depth,
- const char * prefix,
- const struct tpax_dirent * parent)
+ struct tpax_dirent * dent)
{
int fd;
+ int fdat;
+ int depth;
bool fkeep;
long nbytes;
struct dirent * dirent;
struct dirent * dirents;
- struct tpax_unit_ctx * unit;
+ struct tpax_unit_ctx * uctx;
struct stat st;
uintptr_t addr;
- /* fake uctx for recursion items */
- unit = 0;
+ /* init */
+ fdat = dent->fdat;
+ depth = dent->depth;
- if (dent && tpax_get_unit_ctx(
- dctx,dent->fdat,dent->dirent.d_name,
- &unit) < 0)
+ /* uctx on the fly */
+ if (tpax_get_unit_ctx(
+ dctx,fdat,
+ dent->dirent.d_name,
+ &uctx) < 0)
return TPAX_NESTED_ERROR(dctx);
- uctx = dent ? unit : uctx;
-
/* verify that recursion item is still a directory */
- if (unit && !S_ISDIR(unit->st->st_mode))
+ if (!S_ISDIR(uctx->st->st_mode))
return tpax_archive_append_ret(
TPAX_CUSTOM_ERROR(dctx,TPAX_ERR_FLOW_ERROR),
- unit);
-
- /* append directory entry to archive */
- if (tpax_archive_append_one(
- dctx,uctx,0,
- tpax_driver_fdcwd(dctx),
- prefix,0,0) < 0)
- return tpax_archive_append_ret(
- TPAX_NESTED_ERROR(dctx),
- unit);
+ uctx);
/* obtain buffer for file-system directory entries */
dirents = tpax_get_driver_getdents_buffer(dctx);
@@ -518,10 +506,10 @@ static int tpax_archive_append_dir(
depth++;
/* open directory and obtain first directory entries */
- if ((fd = openat(fdat,*uctx->path,O_RDONLY|O_DIRECTORY|O_CLOEXEC,0)) < 0)
+ if ((fd = openat(fdat,dent->dirent.d_name,O_RDONLY|O_DIRECTORY|O_CLOEXEC,0)) < 0)
return tpax_archive_append_ret(
TPAX_SYSTEM_ERROR(dctx),
- unit);
+ uctx);
nbytes = tpax_getdents(fd,dirents,TPAX_DIRENT_BUFLEN);
@@ -531,7 +519,7 @@ static int tpax_archive_append_dir(
if (nbytes < 0)
return tpax_archive_append_ret(
TPAX_SYSTEM_ERROR(dctx),
- unit);
+ uctx);
/* iterate */
for (; nbytes>0; ) {
@@ -546,30 +534,21 @@ static int tpax_archive_append_dir(
if (fstatat(fd,dirent->d_name,&st,AT_SYMLINK_NOFOLLOW))
return tpax_archive_append_ret(
TPAX_SYSTEM_ERROR(dctx),
- unit);
+ uctx);
if (S_ISDIR(st.st_mode)) {
dirent->d_type = DT_DIR;
}
}
- if (dirent->d_type == DT_DIR) {
- if (tpax_archive_append_queue_item(
- dctx,dirent,
- parent,0,unit,depth,
- TPAX_ITEM_IMPLICIT,
- fd,&fkeep) < 0)
- return tpax_archive_append_ret(
- TPAX_NESTED_ERROR(dctx),
- unit);
- } else {
- if (tpax_archive_append_one(
- dctx,0,dirent,fd,prefix,
- 0,*uctx->path) < 0)
- return tpax_archive_append_ret(
- TPAX_NESTED_ERROR(dctx),
- unit);
- }
+ if (tpax_archive_append_queue_item(
+ dctx,dirent,
+ dent,0,depth,
+ TPAX_ITEM_IMPLICIT,
+ fd,&fkeep) < 0)
+ return tpax_archive_append_ret(
+ TPAX_NESTED_ERROR(dctx),
+ uctx);
}
addr = (uintptr_t)dirent;
@@ -586,7 +565,7 @@ static int tpax_archive_append_dir(
if (nbytes < 0)
tpax_archive_append_ret(
TPAX_SYSTEM_ERROR(dctx),
- unit);
+ uctx);
dirent = dirents;
}
@@ -595,7 +574,7 @@ static int tpax_archive_append_dir(
/* all done */
return tpax_archive_append_ret(
fkeep ? 0 : close(fd),
- unit);
+ uctx);
}
int tpax_archive_append_item(
@@ -605,7 +584,8 @@ int tpax_archive_append_item(
(void)dctx;
(void)uctx;
- (void)tpax_archive_append_dir;
+ (void)tpax_archive_append_dir_entries;
+ (void)tpax_archive_append_one;
(void)tpax_append_prefix_item;
return 0;