Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Implement support for SOURCE_DATE_EPOCH in pkg to actually set the timestamp of the files being packages to simplify work on reproducible packages
Baptiste Daroussin committed 10 years ago
commit 69ee4f6417f5fa5f8204e113deb82af3e73bb97f
parent 038f1eb
1 file changed +16 -0
modified libpkg/packing.c
@@ -155,9 +155,11 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
	char *map;
	int retcode = EPKG_OK;
	int ret;
+
	time_t source_time;
	struct stat st;
	struct archive_entry *entry, *sparse_entry;
	bool unset_timestamp;
+
	const char *source_date_epoch;

	entry = archive_entry_new();
	archive_entry_copy_sourcepath(entry, filepath);
@@ -227,6 +229,20 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
		archive_entry_unset_birthtime(entry);
	}

+
	if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) != NULL) {
+
		if (source_date_epoch[strspn(source_date_epoch, "0123456789")] != '\0') {
+
			pkg_emit_error("Bad environement variable "
+
			    "SOURCE_DATE_EPOCH: %s", source_date_epoch);
+
			retcode = EPKG_FATAL;
+
			goto cleanup;
+
		}
+
		source_time = strtoll(source_date_epoch, NULL, 10);
+
		archive_entry_set_atime(entry, source_time, 0);
+
		archive_entry_set_ctime(entry, source_time, 0);
+
		archive_entry_set_mtime(entry, source_time, 0);
+
		archive_entry_set_birthtime(entry, source_time, 0);
+
	}
+

	archive_entry_linkify(pack->resolver, &entry, &sparse_entry);

	if (sparse_entry != NULL && entry == NULL)