5 ms·
I wish modern OSes made this easier. I would love to have an easy bullrtproof way of saying "give me a temp directory for writing, don't let me write anywhere e
by CJefferson 10y ago
I wish modern OSes made this easier. I would love to have an easy bullrtproof way of saying "give me a temp directory for writing, don't let me write anywhere else, clean up my directory after me".
- cheeseprocedure 10y agoChances are that every system this script runs on has "mktemp," and trapping exit makes it easy to clean up when things are finished. https://www.mktemp.org/manual.html https://www.mktemp.org/manual.html http://redsymbol.net/articles/bash-exit-traps/ http://redsymbol.net/articles/bash-exit-traps/
- peterwwillis 10y agoYep, makes it much simpler to write scripts like this https://github.com/psypete/public-bin/blob/public-bin/src/stage_git_app.sh https://github.com/psypete/public-bin/blob/public-bin/src/st... (run an application that's stored in git, but in a temp working directory, and clean up after)
- CJefferson 10y agoBut, how can I make super sure some combination of my mistakes, undefined variables, failed cd commands, race conditions, etc, can't lead to me clearing the wrong directory. I'm sure this is excessive paranoia, but I have never been confident to release a script that classes a directory, I'm to worked about things like subtle differences in how mktemp works on linux and mac for example.
- the8472 10y agoon linux the following might work: - enter a user and mount namespace - mount a tmpfs, e.g. over /tmp - remount everything else as readonly alternatively firejail --overlay-tmpfs <command>
- stuuuuuuuuu 10y agoA good usecase for Docker, maybe? Put the script in a container and let it run wild, then delete the container when it's done.