summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apk_defines.h2
-rw-r--r--src/common.c15
-rw-r--r--src/io_archive.c2
3 files changed, 18 insertions, 1 deletions
diff --git a/src/apk_defines.h b/src/apk_defines.h
index f1b0f8d..3716802 100644
--- a/src/apk_defines.h
+++ b/src/apk_defines.h
@@ -177,6 +177,8 @@ static inline uint32_t get_unaligned32(const void *ptr)
typedef void (*apk_progress_cb)(void *cb_ctx, size_t);
+time_t apk_get_build_time(void);
+
void *apk_array_resize(void *array, size_t new_size, size_t elem_size);
#define APK_ARRAY(array_type_name, elem_type_name) \
diff --git a/src/common.c b/src/common.c
index 14a56a3..580e6d5 100644
--- a/src/common.c
+++ b/src/common.c
@@ -40,3 +40,18 @@ void *apk_array_resize(void *array, size_t new_size, size_t elem_size)
return tmp;
}
+
+time_t apk_get_build_time(void)
+{
+ static int initialized = 0;
+ static time_t timestamp = 0;
+ char *source_date_epoch;
+
+ if (initialized) return timestamp;
+ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+ if (source_date_epoch && *source_date_epoch)
+ timestamp = strtoull(source_date_epoch, NULL, 10);
+ else timestamp = time(NULL);
+ initialized = 1;
+ return timestamp;
+}
diff --git a/src/io_archive.c b/src/io_archive.c
index ccd512a..bfa8efa 100644
--- a/src/io_archive.c
+++ b/src/io_archive.c
@@ -291,7 +291,7 @@ int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae,
PUT_OCTAL(buf.uid, ae->uid);
PUT_OCTAL(buf.gid, ae->gid);
PUT_OCTAL(buf.mode, ae->mode & 07777);
- PUT_OCTAL(buf.mtime, ae->mtime ?: time(NULL));
+ PUT_OCTAL(buf.mtime, ae->mtime ?: apk_get_build_time());
/* Checksum */
strcpy(buf.magic, "ustar ");