Discussion:
time zone in \pdffilemoddate
Add Reply
Ulrike Fischer
2018-11-03 22:00:48 UTC
Reply
Permalink
\pdffilemoddate gives a date with the local time zone, even if
SOURCE_DATE_EPOCH has been set. E.g.

\documentclass{article}
\begin{document}
\pdffilemoddate {article.cls}
\end{document}

gives for me D:20180529230632+02’00’

This is a problem for automated tests, e.g. when embedded files in
the pdf are involved.

Could \pdffilemoddate be changed to always us the "Z" time zone if
SOURCE_DATE_EPOCH is set?
--
Ulrike Fischer
https://www.troubleshooting-tex.de/
Karl Berry
2018-11-04 18:56:57 UTC
Reply
Permalink
Hi Ulrike,

Could \pdffilemoddate be changed to always us the "Z" time zone if
SOURCE_DATE_EPOCH is set?

Will do. Since pdfTeX primitives are involved, I think we should
require that FORCE_SOURCE_DATE also be set.

Thanks for the report/request/suggestion. --karl
Karl Berry
2018-11-13 22:03:35 UTC
Reply
Permalink
Could \pdffilemoddate be changed to always us the "Z" time zone if
SOURCE_DATE_EPOCH is set?

I committed changes to pdftex (r808) and tl (r49145) for this. It won't
show up in native TL until the 2019 release, though some distros may
pick it up soon. Thanks for the suggestion (and to Akira for sending me
the basic patch.)

I took the opportunity to add a check for kpse_in_name_ok on the found
filename, too. (This needs to be checked in other pdf* primitives, and
also done in other engines.) --karl

--- texmfmp.c (revision 806)
+++ texmfmp.c (working copy)
@@ -2219,6 +2219,9 @@
static boolean start_time_set = false;
static time_t start_time = 0;

+static boolean SOURCE_DATE_EPOCH_set = false;
+static boolean FORCE_SOURCE_DATE_set = false;
+
void init_start_time() {
char *source_date_epoch;
unsigned long long epoch;
@@ -2239,6 +2242,7 @@
epoch = 32535291599ULL;
#endif
start_time = epoch;
+ SOURCE_DATE_EPOCH_set = true;
} else
#endif /* not onlyTeX */
{
@@ -2263,6 +2267,7 @@
if (sde_texprim && STREQ (sde_texprim, "1")) {
init_start_time ();
tmptr = gmtime (&start_time);
+ FORCE_SOURCE_DATE_set = true;
} else
#endif /* not onlyTeX */
{
@@ -3150,10 +3155,14 @@
{
struct stat file_data;

- char *file_name = kpse_find_tex(makecfilename(s));
+ const_string orig_name = makecfilename(s);
+ char *file_name = kpse_find_tex(orig_name);
if (file_name == NULL) {
return; /* empty string */
}
+ if (! kpse_in_name_ok(file_name)) {
+ return; /* no permission */
+ }

recorder_record_input(file_name);
/* get file status */
@@ -3163,8 +3172,8 @@
if (stat(file_name, &file_data) == 0) {
#endif
size_t len;
-
- makepdftime(file_data.st_mtime, time_str, /* utc= */false);
+ boolean use_utc = FORCE_SOURCE_DATE_set && SOURCE_DATE_EPOCH_set;
+ makepdftime(file_data.st_mtime, time_str, use_utc);
len = strlen(time_str);
if ((unsigned) (poolptr + len) >= (unsigned) (poolsize)) {
poolptr = poolsize;

Loading...