summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-07-16 20:14:40 +0000
committermidipix <writeonce@midipix.org>2024-07-16 20:14:40 +0000
commita749fdfc3615246713808529cc1ab7e947040ec7 (patch)
treec1c74a4f1f72fe59b2fce60eec25a64f9c4968ff
parenteba861e4ed34d46cd7925b4075d00f0f556afc2b (diff)
downloadtpax-a749fdfc3615246713808529cc1ab7e947040ec7.tar.bz2
tpax-a749fdfc3615246713808529cc1ab7e947040ec7.tar.xz
library api's: _meta_ namespace: make header creation interfaces context independent.
-rw-r--r--include/tpax/tpax.h7
-rw-r--r--src/logic/tpax_archive_write.c12
-rw-r--r--src/meta/tpax_init_ustar_header.c27
3 files changed, 37 insertions, 9 deletions
diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h
index fa685c3..b811987 100644
--- a/include/tpax/tpax.h
+++ b/include/tpax/tpax.h
@@ -184,8 +184,11 @@ tpax_api int tpax_output_error_vector (const struct tpax_driver_ctx *);
tpax_api int tpax_output_error_record (const struct tpax_driver_ctx *, const struct tpax_error_info *);
/* meta interfaces */
-tpax_api int tpax_meta_init_ustar_header (const struct tpax_driver_ctx *, const char *, const struct stat *,
- const char *, struct tpax_ustar_header *);
+tpax_api int tpax_meta_init_ustar_header (const char * pathname, const struct stat *,
+ const char * linkname, struct tpax_ustar_header *);
+
+tpax_api int tpax_meta_init_rustar_header (const char * pathname, const struct stat *,
+ const char * linkname, struct tpax_ustar_header *);
/* low-level interfaces */
tpax_api int tpax_io_create_memory_snapshot(const struct tpax_driver_ctx *, int, const char *,
diff --git a/src/logic/tpax_archive_write.c b/src/logic/tpax_archive_write.c
index a881bd9..f01bb7b 100644
--- a/src/logic/tpax_archive_write.c
+++ b/src/logic/tpax_archive_write.c
@@ -110,6 +110,7 @@ static int tpax_archive_write_impl(
int fdcwd,
int fdout)
{
+ int ret;
struct tpax_unit_ctx * uctx;
struct tpax_ustar_header uhdr;
const struct stat * st;
@@ -210,9 +211,14 @@ static int tpax_archive_write_impl(
dpos = hpos + sizeof(uhdr);
/* header */
- if (tpax_meta_init_ustar_header(
- dctx,apath,st,
- slnk,&uhdr) < 0)
+ if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_RUSTAR) {
+ ret = tpax_meta_init_rustar_header(apath,st,slnk,&uhdr);
+
+ } else if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_USTAR) {
+ ret = tpax_meta_init_ustar_header(apath,st,slnk,&uhdr);
+ }
+
+ if (ret < 0)
return tpax_archive_write_ret(
TPAX_NESTED_ERROR(dctx),
dctx,uctx);
diff --git a/src/meta/tpax_init_ustar_header.c b/src/meta/tpax_init_ustar_header.c
index 2479e28..5078344 100644
--- a/src/meta/tpax_init_ustar_header.c
+++ b/src/meta/tpax_init_ustar_header.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
+#include <stdbool.h>
#include <grp.h>
#include <pwd.h>
#include <sys/stat.h>
@@ -30,12 +31,12 @@ static void tpax_octal_write(char * ch, ssize_t len, uint64_t val)
}
}
-int tpax_meta_init_ustar_header(
- const struct tpax_driver_ctx * dctx,
+static int tpax_meta_init_ustar_header_impl(
const char * path,
const struct stat * st,
const char * linkname,
- struct tpax_ustar_header * uhdr)
+ struct tpax_ustar_header * uhdr,
+ bool frustar)
{
size_t len;
const char * cap;
@@ -140,7 +141,7 @@ int tpax_meta_init_ustar_header(
tpax_octal_write(uhdr->u_mode,ssizeof(uhdr->u_mode),st->st_mode & TPAX_USTAR_MODE_MASK);
/* u_uid, u_gid, u_uname, u_gname */
- if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_RUSTAR) {
+ if (frustar) {
tpax_octal_write(uhdr->u_uid,ssizeof(uhdr->u_uid),0);
tpax_octal_write(uhdr->u_gid,ssizeof(uhdr->u_gid),0);
} else {
@@ -216,3 +217,21 @@ int tpax_meta_init_ustar_header(
/* all done; caller may now change REGFILE to HARDLINK */
return 0;
}
+
+int tpax_meta_init_ustar_header(
+ const char * path,
+ const struct stat * st,
+ const char * linkname,
+ struct tpax_ustar_header * uhdr)
+{
+ return tpax_meta_init_ustar_header_impl(path,st,linkname,uhdr,false);
+}
+
+int tpax_meta_init_rustar_header(
+ const char * path,
+ const struct stat * st,
+ const char * linkname,
+ struct tpax_ustar_header * uhdr)
+{
+ return tpax_meta_init_ustar_header_impl(path,st,linkname,uhdr,true);
+}