Invalid cross-device link when using Eio.Path.load

I am getting the following error when using Eio.Path.load:

Fatal error: exception Eio.Io Fs Permission_denied Unix_error (Invalid cross-device link, "openat2", ""),
    examining <cwd:./trees/index.tree>

As far as I can tell, the file does exist:

let () = List.iter
  (fun p -> Eio.traceln "%s" p)
   Eio.Path.(read_dir (forest.env#cwd / "trees"));
+index.tree

This is quite confusing. First, the behavior is unexpected as it seems that I am able to verify that the file exists, and the error does not really indicate what I can do to fix it (although this is not an issue with the design of Eio itself).

The ./ in the beginning of the path does not seem to be relevant, the following code also works:

let () = List.iter
  (fun p -> Eio.traceln "%s" p)
   Eio.Path.(read_dir (forest.env#cwd / "./trees"));

I am running this executable in a cram test, but the relevant dependencies are specified in the dune file:

(cram
 (applies_to :whole_subtree)
 (deps
  %{bin:forester}
  (glob_files_rec ./forest/*)))

If necessary, I’ll try create a minimal reproduction. This issue does not pertain here as I am not using open_dir anywhere.

Thanks!

Is index.tree a symlink to somewhere outside of the . subtree?

cwd restricts you to things under .; use fs if you want to access other places.

(these are badly named; the distinction is confined vs unconfined, not cwd vs not-cwd)

Well, the file in the test directory is just a regular file. I explicitly mentioned that this was being run in a cram test with dune in case the procedure that dune runs is somehow relevant here, but I think what dune does is that it just copies the relevant files somewhere in the _build directory…

This might be the cause:

ocaml-forester/_build/_tests> ls -l         
total 36
lrwxrwxrwx 1 user users   49 Jan 18 19:39  Iri_resolver -> /home/user/ocaml-forester/_build/_tests/HVYDZBEI
...

Following a symlink through the root directory would cause that error. But if the test is running from HVYDZBEI then the symlink has already been resolved.

That would be useful. I’d also try running it with EIO_BACKEND=posix and check you get a similar error there.

So, replacing cwd with fs mitigates the issue. I don’t know how dune works in detail, I wonder if it is possible to set up the tests that avoids this.