summaryrefslogtreecommitdiffstats
path: root/src/opk
diff options
context:
space:
mode:
Diffstat (limited to 'src/opk')
-rw-r--r--src/opk/write.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/opk/write.c b/src/opk/write.c
index 1b490ee..93ddc74 100644
--- a/src/opk/write.c
+++ b/src/opk/write.c
@@ -20,6 +20,7 @@
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "../defs.h"
#include "../dirent.h"
@@ -41,16 +42,41 @@ _opkg_opk_opk_write_file(void *user_data, size_t size)
}
}
+static int
+_opkg_opk_opk_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_opk_write(struct opkg_opk_opk *opk, const char *file_name)
{
int ret;
+ int64_t mtime;
struct opkg_opk_dirent dirent;
char *buffer;
size_t size;
ret = OPKG_OPK_OK;
+ if (_opkg_opk_opk_source_date_epoch(&mtime) == OPKG_OPK_ERROR) {
+ fputs(_("Error: Missing or invalid SOURCE_DATE_EPOCH\n"),
+ stderr);
+ ret = OPKG_OPK_ERROR;
+ goto out0;
+ }
+
/* Open outer archive. */
opk->file = fopen(file_name, "wb");
if (opk->file == NULL) {
@@ -85,7 +111,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
if (opkg_opk_ustar_write_header(opk->outer_ustar, &dirent, 0644,
0, getpwuid(0)->pw_name,
0, getgrgid(0)->gr_name,
- 4, '-', NULL) != OPKG_OPK_OK) {
+ 4, mtime, '-', NULL) != OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"), stderr);
ret = OPKG_OPK_ERROR;
goto out3;