@@ -4,6 +4,7 @@ import std/random
4
4
import std/ options
5
5
6
6
import ./ n_os
7
+ import ../ pyerrors/ oserr
7
8
8
9
when defined(js): {.error: " pylib tempfile not support JS currently" .}
9
10
import ./ io
@@ -23,7 +24,7 @@ var name_sequence{.threadvar.}: RandomNameSequence
23
24
const RandChars = " abcdefghijklmnopqrstuvwxyz0123456789_"
24
25
25
26
proc initRandomNameSequence(self: var RandomNameSequence) =
26
- let cur_pid = getCurrentProcessId ()
27
+ let cur_pid = n_os.getpid ()
27
28
if cur_pid != self.rng_pid:
28
29
self.rng = initRand()
29
30
self.rng_pid = cur_pid
@@ -46,7 +47,7 @@ proc mktemp*(suffix="", prefix=templ, dir = "", checker=fileExists): string =
46
47
let file = dir / prefix & name & suffix
47
48
if not checker file:
48
49
return file
49
- raise newException(OSError , " No usable temporary filename found" )
50
+ raise newException(FileNotFoundError , " No usable temporary filename found" )
50
51
51
52
52
53
proc candidate_tempdir_list(): seq [string ] =
@@ -279,11 +280,9 @@ proc TemporaryDirectory*(suffix=sNone, prefix=sNone, dir=sNone, ignore_cleanup_e
279
280
280
281
proc cleanup* (self: TemporaryDirectoryWrapper) =
281
282
if self.delete:
282
- try :
283
+ tryOsOp not self.ignore_cleanup_errors :
283
284
removeDir self.name
284
- except OSError:
285
- if not self.ignore_cleanup_errors:
286
- raise # XXX: see Py's TemporaryDirectory._rmtree for real impl
285
+ # XXX: see Py's TemporaryDirectory._rmtree for real impl
287
286
288
287
proc close* (self: TemporaryDirectoryWrapper) =
289
288
# # used to be called in `with` stmt (Python's doesn't have this)
0 commit comments