Sample Header Ad - 728x90

Improving mktemp

2 votes
2 answers
2433 views
I am wondering how to best improve on mktemp for use with encrypted containers or file systems. The issue that I am dealing with is that I would like my shell scripts to store temporary files inside the file system that contains the working directory, if possible. The normal behaviour of mktemp seems to be to use a root path specified in an environment variables or /tmp. This will, however, routinely leak temporary data to unencrypted locations if I am working with files inside encrypted containers. The idea is to first check the presence of a tmp directory in the mount point of the current file system and to use /tmponly as a last resort. How can I reliably (and efficiently) realize that. **Edit** A possible way to identify the mount directory of a given path is the following dir=realpath [path]; res=1; while [ $res -ne 0 ]; do dir="${dir%/*}"; mountpoint -q "$dir/"; res=$?; done; echo "$dir"; I am not sure, however, if that is the most efficient one.
Asked by highsciguy (2614 rep)
Jan 5, 2018, 09:48 PM
Last activity: Apr 11, 2019, 04:36 AM