Skip to content

Commit 3f1f114

Browse files
committed
break(oserr): unexport pathsAsOne, new tryOsOp accepts 2 or 0 paths
1 parent ae1671e commit 3f1f114

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/pylib/Lib/os_impl/path.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ proc getsize*[T](filename: PathLike[T]): int =
6464
int statAttr(filename, st_size)
6565
6666
func samefile*(a, b: PathLike): bool =
67-
tryOsOp(pathsAsOne(a, b)): result = samefile(a.fspath, b.fspath)
67+
tryOsOp(a, b): result = samefile(a.fspath, b.fspath)
6868
6969
template split2Via(p, fn) =
7070
let t = fn $p

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,5 @@ else:
317317
raiseExcWithPath2(src, dst)
318318
319319
proc link*[T](src, dst: PathLike[T]) =
320-
pathsAsOne(src, dst).tryOsOp:
320+
tryOsOp(src, dst):
321321
createHardlink($src, $dst)

src/pylib/Lib/shutil.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ template copyGen(pyname, impl) =
8989
let
9090
ssrc = $src
9191
sdst = $dst
92-
pth = pathsAsOne(src, dst)
9392
cpOptions = if follow_symlinks: {cfSymlinkFollow} else: {cfSymlinkAsIs}
9493
if sameFile(ssrc, sdst):
9594
raise newException(SameFileError, pth)
96-
pth.tryOsOp: impl(ssrc, sdst, options=cpOptions)
95+
tryOsOp(src, dst): impl(ssrc, sdst, options=cpOptions)
9796
9897
copyGen copyfile, copyFileImpl
9998

src/pylib/pyerrors/oserr.nim

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,41 @@ proc raiseExcWithPath*(p: PathLike){.sideEffect.} =
155155
let oserr = osLastError()
156156
p.raiseExcWithPath(oserr)
157157

158-
func pathsAsOne*[T](a, b: PathLike[T], sep = " -> "): string =
158+
func pathsAsOne[T](a, b: PathLike[T], sep = " -> "): string =
159159
## used when there are two pathes that needs to be reported in error message.
160160
## called by `raiseExcWithPath2`_
161161
a.pathrepr & sep & b.pathrepr
162162
163163
proc raiseExcWithPath2*(src, dst: PathLike) =
164164
pathsAsOne(src, dst).raiseExcWithPath()
165165
166-
template tryOsOp*(p: PathLike, body) =
166+
template tryOsOpAux(body, excHandleBody){.dirty.} =
167167
bind raiseExcWithPath
168168
try: body
169169
except OSError as e:
170+
excHandleBody
171+
172+
template tryOsOp*(p: PathLike, body) =
173+
bind tryOsOpAux
174+
tryOsOpAux(body):
170175
p.raiseExcWithPath(e.errorCode.OSErrorCode)
171176
177+
template tryOsOp*(p: PathLike, raiseCond: bool, body) =
178+
bind raiseExcWithPath
179+
tryOsOpAux(body):
180+
if raiseCond:
181+
p.raiseExcWithPath(e.errorCode.OSErrorCode)
182+
183+
template tryOsOp*(raiseCond: bool, body) =
184+
bind raiseExcWithPath
185+
tryOsOpAux(body):
186+
if raiseCond:
187+
raise newPyOSError(e.errorCode.cint, e.msg)
188+
189+
template tryOsOp*(p1, p2: PathLike, body) =
190+
bind pathsAsOne
191+
pathsAsOne(p1, p2).tryOsOp body
192+
172193
when InJs:
173194
proc errnoMsgOSErr(errnoCode: OSErrorCode): string = jsErrnoMsg(errnoCode)
174195
proc errnoMsg*(errno: cint): string = jsErrnoMsg(errno.OSErrorCode)

0 commit comments

Comments
 (0)