Skip to content

phar: honor SOURCE_DATE_EPOCH for timestamps #6564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
4: metadata-len
+: metadata
*/
mytime = time(NULL);
mytime = source_date_epoch_time(NULL);
phar_set_32(entry_buffer, entry->uncompressed_filesize);
phar_set_32(entry_buffer+4, mytime);
phar_set_32(entry_buffer+8, entry->compressed_filesize);
Expand Down
16 changes: 16 additions & 0 deletions ext/phar/phar_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,22 @@ static inline enum phar_fp_type phar_get_fp_type(phar_entry_info *entry)
return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type;
}

static inline time_t source_date_epoch_time(time_t *tloc)
{
zend_string *str = php_getenv("SOURCE_DATE_EPOCH", sizeof("SOURCE_DATE_EPOCH")-1);

if (str) {
time_t t = strtoul(ZSTR_VAL(str), NULL, 10);

zend_string_release(str);
if (tloc) {
*tloc = t;
}
return t;
}
return time(tloc);
}

static inline zend_off_t phar_get_fp_offset(phar_entry_info *entry)
{
if (!entry->is_persistent) {
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static int phar_stream_flush(php_stream *stream) /* {{{ */
phar_entry_data *data = (phar_entry_data *) stream->abstract;

if (data->internal_file->is_modified) {
data->internal_file->timestamp = time(0);
data->internal_file->timestamp = source_date_epoch_time(0);
ret = phar_flush(data->phar, 0, 0, 0, &error);
if (error) {
php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS, "%s", error);
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
char halt_stub[] = "__HALT_COMPILER();";

entry.flags = PHAR_ENT_PERM_DEF_FILE;
entry.timestamp = time(NULL);
entry.timestamp = source_date_epoch_time(NULL);
entry.is_modified = 1;
entry.is_crc_checked = 1;
entry.is_tar = 1;
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, ch

phar_add_virtual_dirs(phar, path, path_len);
etemp.is_modified = 1;
etemp.timestamp = time(0);
etemp.timestamp = source_date_epoch_time(0);
etemp.is_crc_checked = 1;
etemp.phar = phar;
etemp.filename = estrndup(path, path_len);
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int

pass.error = &temperr;
entry.flags = PHAR_ENT_PERM_DEF_FILE;
entry.timestamp = time(NULL);
entry.timestamp = source_date_epoch_time(NULL);
entry.is_modified = 1;
entry.is_zip = 1;
entry.phar = phar;
Expand Down