Skip to content

Commit

Permalink
Merge pull request #569 from talex5/fix-empty-path
Browse files Browse the repository at this point in the history
Fix handling of empty path strings
  • Loading branch information
talex5 authored Jul 3, 2023
2 parents 75c27bf + c87893c commit 1c891a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib_eio/path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let ( / ) (dir, p1) p2 =
| p1, p2 -> (dir, Filename.concat p1 p2)

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

let open_in ~sw ((t:#Fs.dir), path) =
try t#open_in ~sw path
Expand Down
8 changes: 4 additions & 4 deletions lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class dir ~label (fd : Low_level.dir_fd) = object
(flow fd :> <Eio.File.rw; Eio.Flow.close>)

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

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

method close =
Expand Down Expand Up @@ -437,8 +437,8 @@ let stdenv ~run_event_loop =
let stdin = source Eio_unix.Fd.stdin in
let stdout = sink Eio_unix.Fd.stdout in
let stderr = sink Eio_unix.Fd.stderr in
let fs = (new dir ~label:"fs" Fs, ".") in
let cwd = (new dir ~label:"cwd" Cwd, ".") in
let fs = (new dir ~label:"fs" Fs, "") in
let cwd = (new dir ~label:"cwd" Cwd, "") in
object (_ : stdenv)
method stdin = stdin
method stdout = stdout
Expand Down
2 changes: 2 additions & 0 deletions tests/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,14 @@ Reading directory entries under `cwd` and outside of `cwd`.
Path.with_open_dir (cwd / "readdir") @@ fun tmpdir ->
try_mkdir (tmpdir / "test-1");
try_mkdir (tmpdir / "test-2");
try_read_dir tmpdir;
try_read_dir (tmpdir / ".");
try_read_dir (tmpdir / "..");
try_read_dir (tmpdir / "test-3");;
+mkdir <cwd:readdir> -> ok
+mkdir <readdir:test-1> -> ok
+mkdir <readdir:test-2> -> ok
+read_dir <readdir> -> ["test-1"; "test-2"]
+read_dir <readdir:.> -> ["test-1"; "test-2"]
+Eio.Io Fs Permission_denied _, reading directory <readdir:..>
+Eio.Io Fs Not_found _, reading directory <readdir:test-3>
Expand Down

0 comments on commit 1c891a4

Please sign in to comment.