Skip to content

Commit 4b14bbf

Browse files
committed
feat(Lib/os): rmdir supports dir_fd
1 parent 8af12d9 commit 4b14bbf

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,40 @@
33
import ../common
44
import ./mkrmdirImpl
55

6+
import ./pyCfg
7+
import ./chkarg
8+
9+
when not InJS:
10+
importConfig [
11+
os
12+
]
13+
else:
14+
template decl(f, val) =
15+
const `HAVE f` = val
16+
decl unlinkat, false
17+
18+
proc rmdir*(p: PathLike, dir_fd: int) =
19+
sys.audit("os.rmdir", p, dir_fd)
20+
var res: cint
21+
when HAVE_UNLINKAT:
22+
var unlinkat_unavailable = false
23+
if dir_fd != DEFAULT_DIR_FD:
24+
when HAVE_UNLINKAT_RUNTIME:
25+
res = unlinkat(dir_fd.cint, cstring $p, AT_REMOVEDIR)
26+
else:
27+
unlinkat_unavailable = true
28+
res = -1
29+
else:
30+
rawRemoveDir(p)
31+
else:
32+
rawRemoveDir(p)
33+
when HAVE_UNLINKAT:
34+
if unlinkat_unavailable:
35+
argument_unavailable_error("dir_fd")
36+
if res != 0:
37+
raiseExcWithPath(p)
38+
639
proc mkdir*(p: PathLike, mode=0o777, dir_fd: int){.error: "not implement".}
7-
proc rmdir*(p: PathLike, dir_fd: int){.error: "not implement".}
840

941
proc rmdir*(path: PathLike) =
1042
sys.audit("os.rmdir", path, -1)

0 commit comments

Comments
 (0)