Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
mktempdir() should provide an option of a prefix very similar to you can do with mkdtemp in posix #22922
I think it may help if
The discussion thread on this topic can be seen here: https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020
Cf. the previous PR #13969: it tried to allow passing a suffix to
Line 220 file.jl has:
jul - is sent as the fixed prefix. The prefix could be made a parameter.
For non-windows platforms
mkdtemp with fixed "tmpXXXXXXX" format is used that can be changed to something like "cccXXXXXXX" where ccc will be provided by developer or can be tmp by default.
I think it's important we clarify and agree on the ideal implementation.
Prefix provision is for module developers so that they can identify their temp files easily and do some debugging or cleanup activity. It's not going to be a most used functionality as such. Default will be most common.
The whole question here should be whether you are looking at Julia as a platform or OS as the platform. Ideally, a cross platform behavior of APIs should not be dependent on the underlying API used in the platform. Julia platform can use a common minimum behavior but for any advanced user the system APIs are always there to implement additional behaviors.
Hence, my first check-in truncated the number of characters to 3 for character lengths higher than 3 and ignored the prefix for prefix length lesser than 3 characters.
One additional restriction that can be imposed is prefix can only be ASCII or in my opinion base85 charsets other than the characters that cannot be technically part of a file path like: "/|*$" etc. which is not supported either in any of the OS as a file path or can technically complicate shell script writing.
Non-printable characters should be avoided as those can be considered malicious by a discerning system admin.
Without this clarity it may be confusing for a user trying to achieve cross platform behavior.
I think the implementation is taking longer than what I originally estimated and may not have the time to complete the task. May request someone to take up from here and finish the implementation the way you feel ideal for Julia as a platform.
I will check-in all the code with style issues fixed to best my knowledge so that someone can look into addressing the most ideal behavior if that's agreed.
While I wished I could spend more time on the PR (#22998), with my personal engagements elsewhere it may not be practical for me to commit further on it now. My apologies for the same. Whoever is interested can work on the master branch and take the PR to a closure. I will be happy to blanket approve any pull request on that branch in case that comes my way. I have already branched out my sandbox so there are no issues there.
However, some implementation challenges came up due to system implementation of libc, glibc or system specific user APIs which led to some API behavioral differences in each platform.
Here are certain behavioral expectations based on which the documentation or tests may change.
Ideally, if there is a possibility of filename not properly get printed on a terminal, there is a general confusion on malicious behavior.
Recommended: Use of base-85 charset can be safe and removal of support for all characters which cannot be on a file name like "/|$" etc. taking the combination of all such characters in all known platforms. This can be enforced in API or can be left to user as a best practice recommendation.
If mktemp is not looked as a POSIX like mktemp() verbatim, then it technically can. However, the current Windows API used does not have ability to support a suffix. mktempdir() may not need a suffix but flexibility and alignment of behavior with mktemp() does no harm.
tempname() in Unix is based on tempnam() which is not safe, hence that method can be deprecated. Issue #22949
All the user level APIs like tempname() can be carried out in the Julia code and only open and close kind of call can be used from the system. This kind of implementation is provided in Python. This may remove all system level limitations like:
a. 3 character prefix in Windows
On implementing tempname() there may need to establish there are no potential race condition across 2 Julia processes.