summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-30 16:45:17 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-30 21:17:42 (EDT)
commit4cc0d685f1d741e84f126ca1eb91f16b602d023d (patch)
treedb258997b7240d78670acf75060febbe717932f6
parentce9008874a492de45c7257f50fafa8c10d2c1eab (diff)
ustar: Set mtime in written header
-rw-r--r--src/ustar.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ustar.c b/src/ustar.c
index 0ecf36a..a2ab0f8 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -265,6 +265,23 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char **buffer, size_t *size)
return OPKG_OPK_OK;
}
+static int
+_opkg_opk_ustar_source_date_epoch(int64_t *mtime)
+{
+ char *env;
+ char *end;
+
+ env = getenv("SOURCE_DATE_EPOCH");
+ if (env == NULL) {
+ return OPKG_OPK_ERROR;
+ }
+ *mtime = strtol(env, &end, 10);
+ if (*end != '\0') {
+ return OPKG_OPK_ERROR;
+ }
+ return OPKG_OPK_OK;
+}
+
int
opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
struct opkg_opk_dirent *dirent, uint16_t mode,
@@ -272,6 +289,7 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
uint64_t size, char type, const char *linkname)
{
size_t linkname_len;
+ int64_t mtime;
uint32_t chksum;
size_t i;
char *header_uc;
@@ -320,6 +338,11 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
memset(ustar->header.linkname, 0,
sizeof(ustar->header.linkname) - linkname_len);
+ if (_opkg_opk_ustar_source_date_epoch(&mtime) == OPKG_OPK_ERROR) {
+ return OPKG_OPK_ERROR;
+ }
+ sprintf(ustar->header.mtime, "%o", mtime);
+
strcpy(ustar->header.magic, "ustar");
memcpy(ustar->header.version, "00", 2);
chksum = 0;