mIRC Home    About    Download    Register    News    Help

Print Thread
$tempfn #267563 10/08/20 04:27 AM
Joined: Jan 2004
Posts: 1,385
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,385
Implied by /help without being specifically stated is that the random filename evades filenames which already exist. From testing a high number of repetitions, I was unable to find it returning an existing filename.

However, it does not evade strings which were used to create subfolders below $mircdir, as shown by this snippet. This alias is slow, and will create 9 subfolders below $mircdir, but should repeat more than enough times to report several foldername collisions:

Code
//var %digit 1 , %reps 999999 | while (%digit isnum 1-9) { mkdir $+(mirc,%digit,00001.tm_) | inc %digit } | while (%reps) { var %a $tempfn | if (*00001* iswm %a) { echo 4 -a %a $isdir(%a) } | dec %reps }



If my guess is correct, this means the normal usage of temp filenames risks collision with $mircdir\foldernames of this pattern, which might eventually cause rename+delete used by /write to fail. To prevent that potential glitch, users running the above command should also remove those 9 foldernames with:

Code
//var %digit 1 | while (%digit isnum 1-9) { rmdir $+(mirc,%digit,00001.tm_) | inc %digit }



A potential enhancement for this identifier could be having an optional $tempfn(pathname), which defaults as $mircdir, allowing scripts to create not-already-taken filenames within other folders than $mircdir itself.

Re: $tempfn [Re: maroon] #267570 10/08/20 09:36 PM
Joined: Dec 2002
Posts: 4,795
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,795
Thanks for your bug report. Technically, yes, if a scripter intentionally creates folder names that use the same temporary filename format as $tempfn, ie. "mircN.tm_", this will eventually happen. However, in practice, unless a scripter is purposefully trying to break $tempfn, this will never be an issue.

That said, I can see how some scripters might try to use $tempfn to create temporary folder names.

I will add a folder existence check to $tempfn and change the description in the help file to say that it works for creating temporary file or folder names.