-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
IfFileExists incorrectly caches results #1571
Comments
Caching here is by-design - file operations are slow, and thus looking up a file's existence multiple times is not desirable. The working assumption for a (La)TeX run is that as a batch process, if files exist at the start of the run, they will be available throughout. |
Code comment in % To avoid repeated reading of files we need to cache the loading:
% this is important as the code here is used by \emph{all} file checks.
% The same marker is used in the \LaTeXe{} kernel, meaning that we get a
% double-saving with for example \cs{IfFileExists}. As this is all about
% performance, we use the low-level approach for the conditionals. For
% a file already seen, the size is reported as $-1$ so it's distinct from
% any non-cached ones. |
BTW, it's a relatively new feature, introduced in the 2023-06-01 release. See Lines 416 to 422 in 051cfdb
|
I see. Would it be a nontrivial change to support cache bypass as an option to If that would be difficult to add to LaTeX3, I'll copy over (and rename) the simpler, more straightforward LaTeX2ε implementation of |
@spakin I've just added latex3/latex3#1635 to the |
@spakin If you need a temporary hack, use \ExplSyntaxOn
\cs_gset_protected:Npn \file_forget:n #1
{ \cs_undefine:c { __file_seen_ \file_full_name:n {#1} : } }
\ExplSyntaxOff in the preamble then \ExplSyntaxOn
\file_forget:n {<name>}
\ExplSyntaxOff at the point you delete the file. |
@josephwright: Thanks for writing latex3/latex3#1635 and for providing a temporary hack. Much appreciated. |
Scott, the team has decided to offer that interface only on the L3 layer level so |
If we want |
I thought that would happen rather automatically any time soon, eg when you prepare a new upload to ctan. I meant the one you hinted at for January. I don't think it really needs to be earlier just for that (only means extra work for the CTAN maintainers). |
Brief outline of the bug
Once
\IfFileExists
determines that a file exists, it remembers this fact and subsequently neglects to check if the file has ceased to exist.Minimal example showing the bug
Run with LuaLaTeX:
(Derived from @davidcarlisle's answer to https://tex.stackexchange.com/questions/611391/delete-a-file-using-luacode.)
\IfFileExists
should typeset NO (assuming you don't have the.zzz
file it's looking for).\IfFileExists
should typeset YES because the code used afilecontents
environment to create the.zzz
file.\IfFileExists
should typeset NO because the code deleted the.zzz
file using Lua'sos.remove
function. However, because\IfFileExists
incorrectly remembers the previous true path it takes that path again and erroneously outputs YES.Log file (required) and possibly PDF file
iffileexists.log
iffileexists.pdf
Possible solution
I'm no LaTeX3 expert, but it looks to me like the caching may originate in
\__file_full_name_aux:n
. Perhaps retaining only the false path will solve the problem?The text was updated successfully, but these errors were encountered: