Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of empty path strings #569

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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