Skip to content
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

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

Open
kayb94 opened this issue Nov 7, 2018 · 2 comments
Open

Comments

@kayb94
Copy link

kayb94 commented Nov 7, 2018

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
Copy link
Owner

reitzig commented Nov 8, 2018

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:

  • Reject any path that's outside of the working/job directory (which?).
  • If the tmp directory exists and wasn't created by ltx2any (marked by checking/creating a special file?), reject it.
  • Create a special flag that creates the temp folder in /tmp (or equivalent).
  • Default to a /tmp location if -c is given.

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

@reitzig reitzig changed the title '-t' Flag with '-c' deletes more than expected Be more careful about polluting/deleting directories specified by -t Nov 8, 2018
@kayb94
Copy link
Author

kayb94 commented Nov 19, 2018

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants