The file names returned by the Lua os.tempname
function are weak in two respects
- Unlike most other languages it is not possible to define a custom prefix for the file name
- The
_6char
suffix that is generated can, with brute force but nevertheless, be guessed
I have at times used a, salted, MD5 of the current epoch time + a random number. About the only reason why that "feels" like a better solution is the length of the file name string.
Is there a way to generate better ( = longer?) file names?
In other words, either you use what's available in Lua, or you write your own function. However, even if you use hashes, random numbers, and so on, you are still dealing with probability: Such file could exist there since the uniqueness is not guaranteed by the OS in this case.
By the way, consider use of
io.tmpfile
instead ofos.tmpname
.