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

Cygwin internal installation should set noacl in /etc/fstab for /cygdrive mount #5781

Closed
dra27 opened this issue Jan 12, 2024 · 0 comments · Fixed by #5796
Closed

Cygwin internal installation should set noacl in /etc/fstab for /cygdrive mount #5781

dra27 opened this issue Jan 12, 2024 · 0 comments · Fixed by #5796

Comments

@dra27
Copy link
Member

dra27 commented Jan 12, 2024

By default, Cygwin attempts to preserve POSIX permissions on files in mount points. This generally results in chaos, and doesn't make sense for native Windows opam switches (we may be using Cygwin commands to build and install things, but the result is native Windows).

It can also cause "interesting" errors. The issue is typically side-stepped by the default ACL on a user's profile directory (so the default will usually work). The following repro case demonstrates the issue, which can also be seen with opam 2.0.10 from "OCaml for Windows" ("OCaml for Windows" mostly side-steps the problem because the opam root is by default within a Cygwin /home directory).

C:\>opam config report
# opam config report
# opam-version         2.2.0~alpha4~dev (a358d94e412be5ae22054a4dc920cca2fda49821)
# self-upgrade         no
[ERROR] Opam has not been initialised, please run `opam init'
# read-state           OpamStd.OpamSys.Exit(50)

C:\>md Test

C:\>icacls Test
Test BUILTIN\Administrators:(I)(OI)(CI)(F)
     NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
     BUILTIN\Users:(I)(OI)(CI)(RX)
     NT AUTHORITY\Authenticated Users:(I)(M)
     NT AUTHORITY\Authenticated Users:(I)(OI)(CI)(IO)(M)

Successfully processed 1 files; Failed processing 0 files

So C:\Test is a root directory with default permissions (Windows 10/11). Make that OPAMROOT and the init:

Environment setup
C:\>set OPAMROOT=C:\Test

C:\>opam init --cygwin-internal-install --no-git-location -a --bare sunset git+https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
[WARNING] Flag --cygwin-internal-install is experimental, there is no guarantee that it will be kept; avoid using it in scripts.
[WARNING] Flag --no-git-location is experimental, there is no guarantee that it will be kept; avoid using it in scripts.
No configuration file found, using built-in defaults.

<><> Unix support infrastructure ><><><><><><><><><><><><><><><><><><><><><><><>
[NOTE] Configured with internal Cygwin install for depexts
Checking for available remotes: git, mercurial.
  - you won't be able to use rsync and local repositories unless you install the rsync command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.


<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[sunset] Initialised

Add GCC manually and create a mingw-w64 switch:

C:\>C:\Test\.cygwin\setup-x86_64.exe --quiet-mode --no-admin --no-desktop --no-startmenu --root C:\Test\.cygwin\root --site https://cygwin.mirror.constant.com --packages mingw64-x86_64-gcc-core

C:\>Starting cygwin install, version 2.926
User has NO backup/restore rights
User has NO symlink creation right
io_stream_cygfile: fopen(/etc/setup/setup.rc) failed 2 No such file or directory
Current Directory: C:\
root: C:\Test\.cygwin\root user
Changing gid back to original
Selected local directory: C:
mbox : Could not change dir to C:: Incorrect function.
 [00000001]
net: Preconfig
site: https://cygwin.mirror.constant.com/
solving: 1 tasks, update: no, use test packages: no
solving: 8 tasks, update: no, use test packages: no
Augmented Transaction List:
   0 install libisl23                                0.26-1
   1 install libmpc3                                 1.3.1-1
   2 install mingw64-x86_64-binutils                 2.41-3
   3 install mingw64-x86_64-windows-default-manifest 6.4-1
   4 install mingw64-x86_64-winpthreads              11.0.1-1
   5 install mingw64-x86_64-headers                  11.0.1-1
   6 install mingw64-x86_64-runtime                  11.0.1-1
   7 install mingw64-x86_64-gcc-core                 11.4.0-1
Registry value set: HKEY_CURRENT_USER\Software\Cygwin\setup\rootdir = "C:\Test\.cygwin\root"
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/x86_64/release/isl/libisl23/libisl23-0.26-1.tar.zst
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/x86_64/release/mpclib/libmpc3/libmpc3-1.3.1-1.tar.zst
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/x86_64/release/mingw64-x86_64-binutils/mingw64-x86_64-binutils-2.41-3.tar.zst
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/noarch/release/mingw64-x86_64-windows-default-manifest/mingw64-x86_64-windows-default-manifest-6.4-1.tar.xz
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/noarch/release/mingw64-x86_64-winpthreads/mingw64-x86_64-winpthreads-11.0.1-1.tar.xz
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/noarch/release/mingw64-x86_64-headers/mingw64-x86_64-headers-11.0.1-1.tar.xz
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/noarch/release/mingw64-x86_64-runtime/mingw64-x86_64-runtime-11.0.1-1.tar.xz
Extracting from file://C:/https%3a%2f%2fcygwin.mirror.constant.com%2f/x86_64/release/mingw64-x86_64-gcc/mingw64-x86_64-gcc-core/mingw64-x86_64-gcc-core-11.4.0-1.tar.zst
running: C:\Test\.cygwin\root\bin\dash.exe "/etc/postinstall/0p_000_autorebase.dash"
running: C:\Test\.cygwin\root\bin\dash.exe "/etc/postinstall/0p_update-info-dir.dash"
running: C:\Test\.cygwin\root\bin\dash.exe "/etc/postinstall/zp_man-db-update-index.dash"
Ending cygwin install

C:\>opam switch create test-5.1.0 --repos=windows-5.0-testing=git+https://github.com/dra27/opam-repository.git#windows-5.0-testing,sunset --packages ocaml-option-mingw,ocaml.5.1.0
Creating repository windows-5.0-testing...
[windows-5.0-testing] Initialised

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml-option-mingw" "ocaml" {= "5.1.0"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
* installed base-bigarray.base
* installed base-threads.base
* installed base-unix.base
* installed ocaml-option-mingw.1
▼ retrieved flexdll.0.43  (https://github.com/ocaml/flexdll/archive/refs/tags/0.43.tar.gz)
* installed flexdll.0.43
▼ retrieved ocaml-variants.5.1.0+options  (https://github.com/ocaml/ocaml/archive/5.1.0.tar.gz)
* installed ocaml-variants.5.1.0+options
* installed ocaml-config.3
* installed ocaml.5.1.0
* installed base-domains.base
* installed base-nnp.base
Done.
# Run for /f "tokens=*" %i in ('opam env --switch=test-5.1.0') do @%i to update the current shell environment

C:\>for /f "tokens=*" %i in ('opam env --switch=test-5.1.0') do @%i

Now try to install ocamlfind:

C:\>opam install ocamlfind
The following actions will be performed:
=== install 1 package
  * ocamlfind 1.9.5

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
▼ retrieved ocamlfind.1.9.5  (http://download.camlcity.org/download/findlib-1.9.5.tar.gz)
[WARNING] .install file is missing .exe extension for src/findlib/ocamlfind
[WARNING] .install file is missing .exe extension for src/findlib/ocamlfind_opt
[WARNING] Automatically adding .exe to C:\Test\test-5.1.0\.opam-switch\build\ocamlfind.1.9.5\src\findlib\ocamlfind.exe

#=== ERROR while installing ocamlfind.1.9.5 ===================================#
Cannot copy C:\Test\test-5.1.0\.opam-switch\build\ocamlfind.1.9.5\src\findlib\ocamlfind.exe to C:\Test\test-5.1.0\bin\ocamlfind.exe (C:\Devel\opam-3\opam.exe: "open" failed on C:\Test\test-5.1.0\bin\ocamlfind.exe: Permission denied).


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ * install ocamlfind 1.9.5
└─
╶─ No changes have been performed

The core issue here is that ocamlfind uses install -d, and the bin directory of the switch now has messed up permissions. The installation can be fixed up with:

C:\>C:\Test\.cygwin\root\bin\bash -c "/bin/sed -i -e 's/binary,/noacl,&/' /etc/fstab"

C:\>icacls C:\Test\test-5.1.0 /q /c /t /reset
Successfully processed 7731 files; Failed processing 0 files

and then the opam install succeeds:

C:\>opam install ocamlfind
The following actions will be performed:
=== install 1 package
  * ocamlfind 1.9.5

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
▼ retrieved ocamlfind.1.9.5  (cached)
[WARNING] .install file is missing .exe extension for src/findlib/ocamlfind
[WARNING] .install file is missing .exe extension for src/findlib/ocamlfind_opt
[WARNING] Automatically adding .exe to C:\Test\test-5.1.0\.opam-switch\build\ocamlfind.1.9.5\src\findlib\ocamlfind.exe
[WARNING] Automatically adding .exe to C:\Test\test-5.1.0\.opam-switch\build\ocamlfind.1.9.5\src\findlib\ocamlfind_opt.exe
[WARNING] C:\Test\test-5.1.0\bin\safe_camlp4 is a script; the command won't be available
* installed ocamlfind.1.9.5
Done.

The edit to /etc/fstab should be done by opam after creating the Cygwin root. cf. ocurrent/ocaml-dockerfile/src-opam/windows.ml#L263-L265:

    @@ run
         {|awk -i inplace "/(^#)|(^$)/{print;next}{$4=""noacl,""$4; print}" %s\etc\fstab|}
         cyg.root

(although opam can of course do this in OCaml, not awk...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants