Skip to content

Commit c7976a5

Browse files
committed
fix(py): os.readlink raises not just FileNotFoundEror,OSError...
fold to use tryOsOp for listdir,readlink
1 parent 08eca1e commit c7976a5

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

src/pylib/Lib/os_impl/listdirx.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import ./listcommon
55

66
proc listdir*[T](p: PathLike[T] = "."): PyList[T] =
77
result = newPyList[T]()
8-
try:
8+
p.tryOsOp:
99
for i in walkDir($p, relative=true, checkDir=true):
1010
result.append i.path
11-
except OSError as e:
12-
let oserr = e.errorCode.OSErrorCode
13-
p.raiseExcWithPath(oserr)

src/pylib/Lib/os_impl/posix_like/links.nim

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,8 @@ else:
242242

243243

244244
proc readlink*[T](path: PathLike[T]): T =
245-
try: result = mapPathLike[T] readlinkImpl $path
246-
except OSError as e:
247-
let errCode = e.errorCode.OSErrorCode
248-
if errCode.isNotFound:
249-
path.raiseFileNotFoundError()
250-
# XXX: may be other errors?
251-
raise
245+
tryOsOp(path):
246+
result = mapPathLike[T] readlinkImpl $path
252247
253248
when defined(windows):
254249
proc check_dir(src_resolved: string): bool =

src/pylib/Lib/os_impl/posix_like/scandirImpl.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,10 @@ template scandirImpl(path){.dirty.} =
150150
dir.closeSync
151151

152152
else:
153-
try:
153+
tryOsOp(spath):
154154
for t in walkDir(spath, relative=true, checkDir=true):
155155
let de = newDirEntry[T](name = t.path, dir = spath, kind = t.kind)
156156
yield de
157-
except OSError as e:
158-
let oserr = e.errorCode.OSErrorCode
159-
path.raiseExcWithPath(oserr)
160157
161158
iterator scandir*[T](path: PathLike[T]): DirEntry[T] = scandirImpl path
162159
iterator scandirIter*[T](path: T): DirEntry[T]{.closure.} =

0 commit comments

Comments
 (0)