pdftex[808] branches/stable: \pdffilemoddate output UTC if envvars

commits+karl at tug.org commits+karl at tug.org
Tue Nov 13 19:39:00 CET 2018


Revision: 808
          http://tug.org/svn/pdftex?view=revision&revision=808
Author:   karl
Date:     2018-11-13 19:39:00 +0100 (Tue, 13 Nov 2018)
Log Message:
-----------
\pdffilemoddate output UTC if envvars set

Modified Paths:
--------------
    branches/stable/doc/manual/ChangeLog
    branches/stable/doc/manual/pdftex-t.tex
    branches/stable/source/src/texk/web2c/lib/ChangeLog
    branches/stable/source/src/texk/web2c/lib/texmfmp.c

Added Paths:
-----------
    branches/stable/tests/10-moddate/
    branches/stable/tests/10-moddate/Makefile
    branches/stable/tests/10-moddate/test-moddate-abs.tex
    branches/stable/tests/10-moddate/test-moddate.tex

Modified: branches/stable/doc/manual/ChangeLog
===================================================================
--- branches/stable/doc/manual/ChangeLog	2018-11-12 19:12:53 UTC (rev 807)
+++ branches/stable/doc/manual/ChangeLog	2018-11-13 18:39:00 UTC (rev 808)
@@ -1,3 +1,9 @@
+2018-11-13  Karl Berry  <karl at freefriends.org>
+
+	* pdftex-t.tex (Invoking \PDFTEX),
+	(\pdffilemoddate): if SOURCE_DATE_EPOCH and FORCE_SOURCE_DATE are
+	both set, return UTC.
+
 2018-01-01  Karl Berry  <karl at freefriends.org>
 
 	* pdftex-t.tex (encodingfile): supported for Type 3 fonts.

Modified: branches/stable/doc/manual/pdftex-t.tex
===================================================================
--- branches/stable/doc/manual/pdftex-t.tex	2018-11-12 19:12:53 UTC (rev 807)
+++ branches/stable/doc/manual/pdftex-t.tex	2018-11-13 18:39:00 UTC (rev 808)
@@ -1323,19 +1323,23 @@
 
 The second, related, environment variable is \type{FORCE_SOURCE_DATE}.
 If this is set to~\type{1}, \TEX's time-related primitives are also
-initialized from the value of \type{SOURCE_DATE_EPOCH}.  These
-primitives are \type{\year}, \type{\month}, \type{\day}, and
-\type{\time}.  If \type{SOURCE_DATE_EPOCH} is not set, setting
-\type{FORCE_SOURCE_DATE} has no effect.  If \type{FORCE_SOURCE_DATE} is
-unset, set to the empty string, or set to~\type{0}, the primitives
-reflect the current time as usual.  Any other value elicits a warning,
-and the current time is used.  (This is useful only if one wants to make
-reproducible \PDF{}s for a set of documents without changing them in any
-way, e.g., an operating system distribution with manuals that use
-\type{\today}.  Except in such unusual circumstances, it is better not
-to set this, and let the \TEX\ primitives retain the meaning they have
-always had.)
+initialized from the value of \type{SOURCE_DATE_EPOCH}. These primitives
+are \type{\year}, \type{\month}, \type{\day}, and \type{\time}. If
+\type{SOURCE_DATE_EPOCH} is not set, setting \type{FORCE_SOURCE_DATE}
+has no effect. If \type{FORCE_SOURCE_DATE} is unset, set to the empty
+string, or set to~\type{0}, the primitives reflect the current time as
+usual. Any other value elicits a warning, and the current time is used.
+(This is useful only if one wants to make reproducible \PDF{}s for a set
+of documents without changing them in any way, e.g., an operating system
+distribution with manuals that use \type{\today}. Except in such unusual
+circumstances, it is better not to set this, and let the \TEX\
+primitives retain the meaning they have always had.)
 
+In addition, if both \type{SOURCE_DATE_EPOCH} and
+\type{FORCE_SOURCE_DATE} are set, \type{\pdffilemoddate} returns a value
+in UTC, ending in \type{Z}. (The values of the environment variables are
+irrelevant in this case.)
+
 Finally, just to have the list of options and basic invocation at hand,
 here is a verbatim listing of the \type{-}\type{-help} output.  All
 options can be specified with one or two dashes and unambiguously
@@ -4174,9 +4178,12 @@
   \Whatever{expandable}}}
 \bookmark{\tex{pdffilemoddate}}
 
-Expands to the modification date of file \Something{general text} in the same
-format as for \type{\pdfcreationdate}, \eg\ it's {\tt \pdffilemoddate
-{./pdftex-t.tex}} for the source of this manual.
+Expands to the modification date of file \Something{general text} in the
+same format as for \type{\pdfcreationdate}, \eg\ it's {\tt
+\pdffilemoddate {./pdftex-t.tex}} for the source of this manual. As of
+version 1.40.20, if the \type{SOURCE_DATE_EPOCH} and
+\type{FORCE_SOURCE_DATE} environment variables are both set,
+\type{\pdffilemoddate} returns a value in UTC, ending in \type{Z}.
 \introduced{1.30.0}
 
 \pdftexprimitive{\Syntax{\Tex{\pdffilesize} \Something{general text}

Modified: branches/stable/source/src/texk/web2c/lib/ChangeLog
===================================================================
--- branches/stable/source/src/texk/web2c/lib/ChangeLog	2018-11-12 19:12:53 UTC (rev 807)
+++ branches/stable/source/src/texk/web2c/lib/ChangeLog	2018-11-13 18:39:00 UTC (rev 808)
@@ -1,3 +1,12 @@
+2018-11-13  Karl Berry  <karl at freefriends.org>
+
+	* texmfmp.c (FORCE_SOURCE_DATE_set, SOURCE_DATE_EPOCH_set): new static.
+	(init_start_time, get_date_and_time): initialize them.
+	(getfilemoddate): use_utc if both vars set.
+	Original suggestion from Ulrike Fischer, tex-live 3 Nov 2018 23:00:48,
+	original patch from Akira Kakuto.
+	(getfilemoddate): also, return nothing if ! kpse_in_name_ok.
+
 2018-11-04  Akira Kakuto  <kakuto at fuk.kindai.ac.jp>
 
 	* openclose.c: cleanup for non-ascii file names (w32 only)

Modified: branches/stable/source/src/texk/web2c/lib/texmfmp.c
===================================================================
--- branches/stable/source/src/texk/web2c/lib/texmfmp.c	2018-11-12 19:12:53 UTC (rev 807)
+++ branches/stable/source/src/texk/web2c/lib/texmfmp.c	2018-11-13 18:39:00 UTC (rev 808)
@@ -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;

Added: branches/stable/tests/10-moddate/Makefile
===================================================================
--- branches/stable/tests/10-moddate/Makefile	                        (rev 0)
+++ branches/stable/tests/10-moddate/Makefile	2018-11-13 18:39:00 UTC (rev 808)
@@ -0,0 +1,27 @@
+# $Id$
+# Public domain.
+
+include ../Common.mak
+
+default: test-moddate test-moddate-abs
+
+test-moddate:
+	# regular
+	$(prog) test-moddate.tex
+	grep "D:2[0-9].*-.*'" test-moddate.log >/dev/null
+	#
+	# just one envvar, still regular.
+	SOURCE_DATE_EPOCH=1 $(prog) test-moddate.tex
+	grep "D:2[0-9].*-.*'" test-moddate.log >/dev/null
+	#
+	# both envvars, force utc.
+	FORCE_SOURCE_DATE=1 SOURCE_DATE_EPOCH=1 $(prog) test-moddate.tex
+	grep "D:2[0-9].*Z " test-moddate.log >/dev/null
+
+test-moddate-abs:
+	# should fail due to openin_any.
+	openin_any=p $(prog) test-moddate-abs.tex
+	! grep "D:2[0-9]" test-moddate-abs.log >/dev/null
+
+clean:
+	$(clean)


Property changes on: branches/stable/tests/10-moddate/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id Revision
\ No newline at end of property
Added: branches/stable/tests/10-moddate/test-moddate-abs.tex
===================================================================
--- branches/stable/tests/10-moddate/test-moddate-abs.tex	                        (rev 0)
+++ branches/stable/tests/10-moddate/test-moddate-abs.tex	2018-11-13 18:39:00 UTC (rev 808)
@@ -0,0 +1,9 @@
+% $Id$
+% Public domain.
+
+\catcode`\{=1 \catcode`\}=2
+
+% Check that \pdffilemoddate fails on system filenames
+% with openin_any=p; see Makefile.
+\message{\pdffilemoddate{/etc/issue}}
+\end


Property changes on: branches/stable/tests/10-moddate/test-moddate-abs.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id Revision
\ No newline at end of property
Added: branches/stable/tests/10-moddate/test-moddate.tex
===================================================================
--- branches/stable/tests/10-moddate/test-moddate.tex	                        (rev 0)
+++ branches/stable/tests/10-moddate/test-moddate.tex	2018-11-13 18:39:00 UTC (rev 808)
@@ -0,0 +1,8 @@
+% $Id$
+% Public domain.
+
+\catcode`\{=1 \catcode`\}=2
+
+% Check that \pdffilemoddate returns UTC with envvars set; see Makefile.
+\message{\pdffilemoddate{\jobname.tex}}
+\end


Property changes on: branches/stable/tests/10-moddate/test-moddate.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id Revision
\ No newline at end of property


More information about the pdftex-commits mailing list