reitzig / ltx2any

Yet another LaTeX build wrapper, with one or two nifty features
GNU General Public License v3.0
59 stars 4 forks source link

Be more careful about polluting/deleting directories specified by -t #114

Open kayb94 opened 5 years ago

kayb94 commented 5 years ago

Hi,

thank you for your work on ltx2any, it is really a handy tool for me to write Latex from vim! However, I encountered some unexpected behavior of the -t flag in combination with the -c flag. I used it roughly like: ltx2any -t /tmp -c FILE I thought, the temporary files would be created there and afterwards only those just created files would be deleted. However, everything in /tmp was deleted (except root's files). I think I figured out it should be used like the following: ltx2any -t /tmp/ltx2any_tmpdir -c FILE The directory is created, the files are put there, and afterwards everything including the directory is removed -- which again is nice.

What do you think? Would it be better to clarify the behavior by making the description in parameters.rb more clear? Or is the behavior better changed? At least this can be pretty dangerous when doing ltx2any -t ~ -c ~/dir/FILE.

I was thinking of something like: Parameter.new(:tmpdir, 't', String, '"#{self[:user_jobname]}#{TMPSUFFIX}"', 'Directory for temporary files. If combined with -c, all contents of the directory including itself is removed afterwards.'),

An even safer approach might be to only accept non-existing directories as parameter (I'd prefer this).

Regards

reitzig commented 5 years ago

Thanks, I'm glad you find the tool useful! :)

You got it exactly right: ltx2any assumes it owns the tmp directory. FWIW, whether you use -t is irrelevant: if you use the default and that directory (jobname_tmp) exists for any reason, ltx2any will usurp it completely.

FWIW, I'd happily default to mktemp -d for the temporary files -- but given that you do frequently have to consult the full log (as least I do) or do other things in the temp folder (e.g. remove PDFs created by TikZ externalization), I have rejected the idea so far.

Would it be better to clarify the behavior

Definitely. I'll check that the help output and documentation are clear about that. We definitely don't want to (accidentally) pollute an important directory with dozens of LaTeX tmp files, let alone delete it!

A related issue is that ltx2any works best if the job directory doesn't contain anything but the LaTeX project you want to build. Big files or, worse, recursive symlinks of expansive subfolders can cause trouble.

An even safer approach might be to only accept non-existing directories as parameter

That won't be helpful if you use it without -c. You want to reuse the temporary files! Outside of -d more, that's a big part of the point of the tool.

Note that storing in /tmp is not ideal in that scenario, either; we have no guarantees that the files stay around (not that it's likely, but inconsistent state might happen), and they'll most certainly be gone after a reboot.

Or is the behavior better changed?

Maybe. Here are some thoughts:

I'll think about it until 1.0. Thanks for the helpful feedback!

kayb94 commented 5 years ago

You're welcome!