LyX sometimes deletes a file and directory instead of making a pdf
Boylan, Ross
Ross.Boylan at ucsf.edu
Fri May 3 03:35:38 UTC 2024
Since I'm not sure this is a bug, or what it's a bug in, I thought I'd post here. First, I'd like to thank all the LyX developers for their work.
The core problem is that when I run `lyx -export pdf2 -v inst\doc\msep_num.lyx` under some conditions-detailed below---the .lyx file and the doc directory it is in are deleted, and no pdf is created in the top-level directory. Here's the accompanying output:
[1] ""
[2] "Running: git ls-files \"msep_num.lyx\" > \"C:/Users/rdboylan/AppData/Local/Temp/3/lyx_tmpdir.PEIeNMGadmvT/lyxvcout.kdsSyY\""
[3] ""
[4] "Running: pdflatex \"msep_num.tex\" > nul"
[5] "This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023) (preloaded format=pdflatex)\r"
[6] " restricted \\write18 enabled.\r"
[7] "entering extended mode\r"
[8] "(./msep_num.tex\r"
[9] "LaTeX2e <2023-06-01> patch level 1\r"
[10] "L3 programming layer <2023-08-03>\r"
[11] "\r"
My guess is that ls-files is failing because it doesn't include the path. There are other reports of problems when the file is not registered with version control (https://tex.stackexchange.com/questions/680698/lyx-and-git-for-version-control) but the failure there was different (a crash).
Why that should make it delete the whole directory I don't know.
Running LyX 2.3.6.1 under Windows Server 2019 Standard, Version 1809. The invocation is from RStudio 2023.12.1+402 running R 4.3.3 ucrt.
Some theories about the problem:
1. The file argument to lyx should not include paths.
2. The path separator is wrong, e.g., use / instead of \. Or I need different escaping.
3. The msep_num.lyx file is in inst/doc/ because of a git mv (and then later a git restore when it got deleted) not git add, and the check is specific to add.
All those concerns point to ambiguities in the documentation; in fact I found no documentation on command line usage in the usual documentation and relied on https://wiki.lyx.org/LyX/ManPage instead.
The behavior is the same regardless of whether an existing msep_num.pdf is present under inst/doc.
Doing a git commit after moving msep_num.lyx under inst/doc did not help.
DETAILS
=======
I am invoking LyX from an R script as part of the build process for a package. The code is
if (.Platform$OS.type == "windows"){
# first part is to get the explicit full path to the executable
regpath <- file.path("SOFTWARE", "LyX", fsep="\\")
v <- readRegistry(regpath, hive = "HLM", maxdepth = 2)
lyxdir <- v[[v$latestVersion]][["(Default)"]]
lyx <- file.path(lyxdir, "bin", "LyX.exe", fsep = "\\")
# execute it
r <- system2(lyx, args = c("--export", "pdf2", "-v", "inst\\doc\\msep_num.lyx"),
stdout=TRUE, stderr=TRUE, invisible = FALSE)
# next command produces the numbered output shown above
print(r)
}
If I execute that code directly from RStudio it works fine. But if I trigger a check from RStudio, which builds the whole package, it fails as described above.
Which seems to rule out all of my theories since they shouldn't care about how the code is invoked (it is in a file boostrap.R and I have selected options to use it).
The 2 ways of running the code must be setting up some differences in the environment (e.g., one might be in an MSYS environment, or maybe WSL), maybe as simple as what environment variables are defined. Though the man page only mentions dependence on LyX-specific environment variables. They may differ in whether they have access to stdin/stdout or the console.
I don't know why LyX is bothering with git at all, and even if it has problems I wouldn't have expected them to delete files and directories. It remains possible that the deletion is being done by R check or build code, but the invocation of git ls-files is clearly from LyX.
Searching through the current master branch of LyX shows only occurrences of "ls-files"; the one at play here seems to be from VCBackend.cpp:
bool GIT::findFile(FileName const & file)
{
// First we check the existence of repository meta data.
if (VCS::checkParentDirs(file, ".git").empty()) {
LYXERR(Debug::LYXVC, "Cannot find GIT meta data for " << file);
return false;
}
// Now we check the status of the file.
TempFile tempfile("lyxvcout");
FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
}
string const fname = onlyFileName(file.absFileName());
LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
<< fname << '\'');
doVCCommandCall("git ls-files " +
quoteName(fname) + " > " +
quoteName(tmpf.toFilesystemEncoding()),
file.onlyPath());
tmpf.refresh();
bool found = !tmpf.isFileEmpty();
LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
return found;
}
I looked for invocations of findFile() but found nothing in them that looked as if it would delete a directory.
I tried lyx -dbg (using the full path for lyx) to get debug options, but none were listed.
Thanks for any help.
Ross
More information about the lyx-devel
mailing list