Skip to content

Commit 1c891a4

Browse files
authored
Merge pull request #569 from talex5/fix-empty-path
Fix handling of empty path strings
2 parents 75c27bf + c87893c commit 1c891a4

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lib_eio/path.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ let ( / ) (dir, p1) p2 =
88
| p1, p2 -> (dir, Filename.concat p1 p2)
99

1010
let pp f ((t:#Fs.dir), p) =
11-
Fmt.pf f "<%t:%s>" t#pp (String.escaped p)
11+
if p = "" then Fmt.pf f "<%t>" t#pp
12+
else Fmt.pf f "<%t:%s>" t#pp (String.escaped p)
1213

1314
let open_in ~sw ((t:#Fs.dir), path) =
1415
try t#open_in ~sw path

lib_eio_linux/eio_linux.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class dir ~label (fd : Low_level.dir_fd) = object
397397
(flow fd :> <Eio.File.rw; Eio.Flow.close>)
398398

399399
method open_dir ~sw path =
400-
let fd = Low_level.openat ~sw ~seekable:false fd path
400+
let fd = Low_level.openat ~sw ~seekable:false fd (if path = "" then "." else path)
401401
~access:`R
402402
~flags:Uring.Open_flags.(cloexec + path + directory)
403403
~perm:0
@@ -409,7 +409,7 @@ class dir ~label (fd : Low_level.dir_fd) = object
409409

410410
method read_dir path =
411411
Switch.run @@ fun sw ->
412-
let fd = Low_level.open_dir ~sw fd path in
412+
let fd = Low_level.open_dir ~sw fd (if path = "" then "." else path) in
413413
Low_level.read_dir fd
414414

415415
method close =
@@ -437,8 +437,8 @@ let stdenv ~run_event_loop =
437437
let stdin = source Eio_unix.Fd.stdin in
438438
let stdout = sink Eio_unix.Fd.stdout in
439439
let stderr = sink Eio_unix.Fd.stderr in
440-
let fs = (new dir ~label:"fs" Fs, ".") in
441-
let cwd = (new dir ~label:"cwd" Cwd, ".") in
440+
let fs = (new dir ~label:"fs" Fs, "") in
441+
let cwd = (new dir ~label:"cwd" Cwd, "") in
442442
object (_ : stdenv)
443443
method stdin = stdin
444444
method stdout = stdout

tests/fs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,14 @@ Reading directory entries under `cwd` and outside of `cwd`.
365365
Path.with_open_dir (cwd / "readdir") @@ fun tmpdir ->
366366
try_mkdir (tmpdir / "test-1");
367367
try_mkdir (tmpdir / "test-2");
368+
try_read_dir tmpdir;
368369
try_read_dir (tmpdir / ".");
369370
try_read_dir (tmpdir / "..");
370371
try_read_dir (tmpdir / "test-3");;
371372
+mkdir <cwd:readdir> -> ok
372373
+mkdir <readdir:test-1> -> ok
373374
+mkdir <readdir:test-2> -> ok
375+
+read_dir <readdir> -> ["test-1"; "test-2"]
374376
+read_dir <readdir:.> -> ["test-1"; "test-2"]
375377
+Eio.Io Fs Permission_denied _, reading directory <readdir:..>
376378
+Eio.Io Fs Not_found _, reading directory <readdir:test-3>

0 commit comments

Comments
 (0)