[latex3-commits] [git/LaTeX3-latex3-latex2e] hotfix/gh422: Remove path from internal file name representation (fixes #422) (fcc1735b)

PhelypeOleinik phelype.oleinik at latex-project.org
Fri Nov 6 03:06:27 CET 2020


Repository : https://github.com/latex3/latex2e
On branch  : hotfix/gh422
Link       : https://github.com/latex3/latex2e/commit/fcc1735bf9f43038fdde228f852617cbe9d54f5f

>---------------------------------------------------------------

commit fcc1735bf9f43038fdde228f852617cbe9d54f5f
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Thu Nov 5 23:06:27 2020 -0300

    Remove path from internal file name representation (fixes #422)
    
    A path can be written several different ways and still lead to the same
    file in the filesystem, so the same package file can be loaded twice as
    long as the path is typed differently (it doesn't even need to point to
    a different file in the system).  The sane solution is to drop the file
    path from all internal bookkeeping and only use it in filesystem lookup
    operations.  This commit introduces `\@currpath` to store the file path
    and `\@currname` now contains only the base name.  This also fixes #421
    although #421 also requires some changes to `xkeyval` because it parses
    `\@filelist` (which contains paths) and looks at `\opt at path/name.ext`.


>---------------------------------------------------------------

fcc1735bf9f43038fdde228f852617cbe9d54f5f
 base/ltclass.dtx | 67 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 55 insertions(+), 12 deletions(-)

diff --git a/base/ltclass.dtx b/base/ltclass.dtx
index b639ae94..8db9a390 100644
--- a/base/ltclass.dtx
+++ b/base/ltclass.dtx
@@ -524,6 +524,14 @@
 %    \end{macrocode}
 %  \end{macro}
 %
+% \begin{macro}{\@currpath}
+%   Path to the current file if explicitly given.
+%   \changes{v1.3u}{2020/11/05}{Macro added}
+%    \begin{macrocode}
+\let\@currpath\@empty
+%    \end{macrocode}
+% \end{macro}
+%
 %  \begin{macro}{\@currname}
 %    Name of current package or option.
 %    \begin{macrocode}
@@ -1719,8 +1727,32 @@
 %<latexrelease>\IncludeInRelease{2020/10/01}%
 %<latexrelease>      {\@onefilewithoptions}{Hooks and unused options issue}%
 \def\@onefilewithoptions#1[#2][#3]#4{%
+%    \end{macrocode}
+%    We have to sanitise file names, so that something like
+% \begin{verbatim}
+%   \usepackage{some/local/path/array}
+%   \usepackage{array}
+% \end{verbatim}
+%    won't load \file{array.sty} twice.  It is remotely possible that
+%    those are two different files, but as a matter of principles, we
+%    will consider that the base file name uniquely identifies a
+%    package, regardless of where it lives.  This assumption already
+%    holds for file hooks, for example, which address the hook to a file
+%    by its base name only.
+%
+%    We'll use \cs{@expl@@@filehook at set@curr at file@@nNN} to parse the
+%    file name and return the \meta{path} and \meta{base+ext} in
+%    separate token lists.  Further ahead, most operations use
+%    \cs{@currname} which doesn't have a path attached to it;  only few
+%    actions prepend \cs{@currpath} to \cs{@currname} (namely loading,
+%    as we have to respect the given path).
+%    \begin{macrocode}
+  \@expl@@@filehook at set@curr at file@@nNN
+    {\@expl@@@filehook at resolve@file at subst@@w #1.#4\@nil}%
+      \reserved at a\reserved at b
   \@pushfilename
-  \xdef\@currname{#1}%
+  \xdef\@currname{\string at makeletter\reserved at a}%
+  \xdef\@currpath{\ifx\reserved at b\@empty\else\reserved at b/\fi}%
   \global\let\@currext#4%
 %    \end{macrocode}
 %    The command \cs{ver@\meta{file}.\meta{ext}} is used to signal that
@@ -1765,10 +1797,12 @@
 %    \end{macrocode}
 %    First we take the \meta{name} and \meta{ext} given in the argument
 %    and check if the file exists, and issue an error otherwise asking
-%    for a correction with \cs{@missingfileerror}.
+%    for a correction with \cs{@missingfileerror}.  For checking if the
+%    file exists we use \cs{@currpath} (usually empty) before
+%    \cs{@currname}.
 %    \begin{macrocode}
-     \IfFileExists{\@currname.\@currext}{}%
-       {\@missing at onefilewithoptions{#2}}%
+     \IfFileExists{\@currpath\@currname.\@currext}{}%
+       {\tracingnone\@missing at onefilewithoptions{#2}}%
 %    \end{macrocode}
 %    If \cs{@currname} is empty (the user replied to the ``Enter file
 %    name'' prompt with \meta{RETURN}), so stop here
@@ -1784,11 +1818,12 @@
 %    do the bookkeeping with \cs{@filehook at file@push}
 %    then call \cs{set at curr@file} to set \cs{@curr at file} (and do any
 %    required substitution), then actually load the class/package with
-%    \cs{load at onefile@withoptions}.
+%    \cs{load at onefile@withoptions}.  \cs{set at curr@file} also needs the
+%    file path.
 %    \begin{macrocode}
        \@disable at packageload@do{\@currname.\@currext}%
          {\@expl@@@filehook at file@push@@
-          \set at curr@file{\@currname.\@currext}%
+          \set at curr@file{\@currpath\@currname.\@currext}%
           \@filehook at set@CurrentFile
 %    \end{macrocode}
 %    \changes{v1.3q}{2020/09/06}
@@ -1812,10 +1847,15 @@
           \expandafter\@swaptwoargs\expandafter
             {\expandafter{\@currpkg at reqd}}%
             {% <
+%    \end{macrocode}
+%    \cs{@currpkg at reqd} doesn't take a path because it is used later to
+%    assign \cs[no-index]{opt at ...} and \cs[no-index]{ver at ...}.
+%    \begin{macrocode}
           \edef\@currpkg at reqd{\@currname.\@currext}%
           \ifx\CurrentFile\CurrentFileUsed
           \else
             \filename at parse\@curr at file
+            \edef\@currpath{\string at makeletter\filename at area}%
             \edef\@currname{\string at makeletter\filename at base}%
             \edef\@currext{\string at makeletter\filename at ext}%
           \fi
@@ -1864,11 +1904,13 @@
 % \end{macro}
 %
 % \begin{macro}{\@missing at onefilewithoptions}
-%    Now the action taken when a file is not found.
+%    Now the action taken when a file is not found.  Path must be
+%    included here as it eventually leads to a file lookup.
 %    \begin{macrocode}
 \def\@missing at onefilewithoptions#1{%
-  \@missingfileerror\@currname\@currext
-  \xdef\@currname{\@missingfile at area\@missingfile at base}%
+  \@missingfileerror{\@currpath\@currname}\@currext
+  \global\let\@currpath\@missingfile at area
+  \global\let\@currname\@missingfile at base
   \global\let\@currext\@missingfile at ext}
 %    \end{macrocode}
 % \end{macro}
@@ -1912,11 +1954,12 @@
     \fi
 %    \end{macrocode}
 %    Now actually load the file (at this point we are certain it exists,
-%    but use \cs{InputIfFileExists} so that file hooks are executed):
+%    but use \cs{InputIfFileExists} so that file hooks are executed).
+%    \cs{@currpath} is needed here too.
 %    \begin{macrocode}
-    \InputIfFileExists{\@currpkg at reqd}{}%
+    \InputIfFileExists{\@currpath\@currpkg at reqd}{}%
       {\@latex at error
-        {The \@cls at pkg\space\@currpkg at reqd\space failed to load.}\@ehd}%
+        {The \@cls at pkg\space\@currpkg at reqd\space failed to load}\@ehd}%
 %-----------------------------------------
 %    \end{macrocode}
 %    In older versions of the code |\@unprocessedoptions| would





More information about the latex3-commits mailing list.