opam icon indicating copy to clipboard operation
opam copied to clipboard

Creation of opam switch fails if the cwd get erased

Open dbuenzli opened this issue 3 years ago • 6 comments

I don't think it's a super important issue so don't hesitate to close if it makes it for easier operations.

But it seems that if you are in a directory, invoke opam switch create to create a non-local switch and then somehow erase that directory you end up with:

[ERROR] Actions cancelled because of Sys_error("No such file or directory")
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [Y/n] n
Fatal error:
Sys_error("No such file or directory")
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
Backtrace:
  Raised at file "src/client/opamSwitchCommand.ml", line 348, characters 4-11
  Called from file "src/client/opamCommands.ml", line 2126, characters 8-177
  Called from file "src/state/opamGlobalState.ml", line 162, characters 14-18
  Re-raised at file "src/core/opamStd.ml", line 1164, characters 4-38
  Called from file "src_ext/cmdliner/src/cmdliner_term.ml", line 27, characters 19-24
  Called from file "src_ext/cmdliner/src/cmdliner.ml", line 27, characters 27-34
  Called from file "src_ext/cmdliner/src/cmdliner.ml", line 106, characters 32-39
  Called from file "src_ext/cmdliner/src/cmdliner.ml", line 136, characters 18-36
  Called from file "src_ext/cmdliner/src/cmdliner.ml", line 251, characters 22-48
  Called from file "src/client/opamMain.ml", line 207, characters 6-64
  Called from file "src/client/opamMain.ml", line 136, characters 6-10

dbuenzli avatar Nov 28 '20 00:11 dbuenzli

Indeed, it's not the most usual case :)
I tried to reproduce (debian), but didn't succeed to fail:

    • create dir
    • opam sw create non local switch to the end
    • remove dir from another terminal
    • opam list on the two terms are ok
    • create dir
    • opam sw create non local switch with a long compiling time
    • remove dir from another terminal, with the switch creation / ocaml compilation didn't end yet
    • switch creation ends correctly
    • opam list on the two terms are ok

Do you have another workflow?

rjbou avatar Dec 01 '20 17:12 rjbou

Do you have another workflow?

"Workflow" is hyperbole :-) but it was 2. I can reproduce on macOS 10.15.7 with:

mkdir /tmp/bla 
cd /tmp/bla
opam switch create 4.06.0

Now in another terminal rm -r /tmp/bla.

[...]
[ERROR] Actions cancelled because of Sys_error("No such file or directory")

dbuenzli avatar Dec 02 '20 15:12 dbuenzli

Ok! I don't have a macos available to test. If you have a moment, can you try to give the full log of the switch creation with a debug level to 3? It is quite long, maybe on a gist

rjbou avatar Dec 15 '20 14:12 rjbou

@rjbou I can give you access to my test mac mini i got off of ebay a couple of months ago. Just send me your public key in DM if you'd want that

kit-ty-kate avatar Dec 18 '20 20:12 kit-ty-kate

Sorry @rjbou I missed your message here you have: https://gist.github.com/dbuenzli/fb5435310654dee8ab0193e1d16122e3

dbuenzli avatar Dec 19 '20 09:12 dbuenzli

Thanks @kit-ty-kate I'll keep this in mind for further mac-related experiments.

On the issue itself: at each process launch, opam retrieve the cwd (to rollback to the good dir), so when the directory is removed, the getcwd() function call errors on mac (but not on deb).

rjbou avatar Jan 06 '21 12:01 rjbou