Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 8bc4835

Browse files
author
Huy Doan
authored
Merge pull request #6 from nigredo-tori/mitigate-5
Make mkdtemp check for pre-existing directories
2 parents 9416fc6 + 3b749ae commit 8bc4835

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tempfile.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ proc mkdtemp*(prefix = "tmp", suffix = "", dir = ""): string =
5959
for x in 0..MAX_RETRIES:
6060
path = mktemp(prefix, suffix, dir)
6161
try:
62-
createDir(path)
63-
return path
62+
# A bit racy, but better than nothing
63+
if not path.existsDir:
64+
createDir(path)
65+
return path
6466
except:
6567
discard
6668
raise newException(IOError, "Unable to create temporary directory")

0 commit comments

Comments
 (0)