mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Remove output file in temporary folder on error
This commit solves two issues: (1) A PDF from a previous run could have been the result of a command that exited with error (e.g. sometimes pdflatex still produces a PDF if it exits with error). If the "View" button were clicked a second time without changing the .lyx file, then the checksum of the .tex file would not have changed so LyX would show the PDF (which was created from the first run that exited with error), and this time LyX would not report the error (because the parsing of the logs only happens when the .tex file is compiled). (2) A myfile.tex that results in no output does not yield a myfile.pdf. Thus, Any myfile.pdf in the temporary directory will not be overwritten. Before this commit, the following scenario was possible: LyX runs pdflatex which processes myfile.tex and no error is given so LyX opens myfile.pdf. However, it could have been the scenario that pdflatex did not exit with error and did not create myfile.pdf, in which case whichever myfile.pdf is being shown is not correct. To see this bug in action, start a new document, type "abc", view the PDF, delete "abc", view the PDF (this correctly gives an error that empty output was created), view the PDF again (this does not give an error because the checksum has not changed). The PDF shown will contain "abc". Note that the above also applies to DVI files and that the fix is general.
This commit is contained in:
parent
6343d9941a
commit
2bfbf75eed
@ -142,6 +142,9 @@ void LaTeX::deleteFilesOnError() const
|
||||
// Also remove the aux file
|
||||
FileName const aux(changeExtension(file.absFileName(), ".aux"));
|
||||
aux.removeFile();
|
||||
|
||||
// Remove the output file, which is often generated even if error
|
||||
output_file.removeFile();
|
||||
}
|
||||
|
||||
|
||||
@ -421,6 +424,15 @@ int LaTeX::run(TeXErrors & terr)
|
||||
|
||||
// Write the dependencies to file.
|
||||
head.write(depfile);
|
||||
if (scanres & NO_OUTPUT) {
|
||||
// A previous run could have left a PDF and since
|
||||
// no PDF is created if NO_OUTPUT, we remove any
|
||||
// existing PDF and temporary files so that an
|
||||
// incorrect PDF is not displayed, which could otherwise
|
||||
// happen if View is run again because the checksum will
|
||||
// be the same so any lingering PDF will be viewed.
|
||||
deleteFilesOnError();
|
||||
}
|
||||
LYXERR(Debug::LATEX, "Done.");
|
||||
return scanres;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user