diff --git a/src/client/opamSolution.ml b/src/client/opamSolution.ml index b0adf8673ea..905d53cd82d 100644 --- a/src/client/opamSolution.ml +++ b/src/client/opamSolution.ml @@ -1189,8 +1189,10 @@ let install_sys_packages ~map_sysmap ~confirm env config sys_packages t = | `Ignore -> bypass t | `Quit -> give_up_msg (); OpamStd.Sys.exit_because `Aborted and print_command sys_packages = + (* Ensure that setup-x86_64.exe exists, so that an invalid command is not + displayed to the user. *) if OpamSysPoll.os_distribution env = Some "cygwin" then - OpamSysInteract.Cygwin.check_setup None; + OpamSysInteract.Cygwin.check_setup ~update:false; let commands = OpamSysInteract.install_packages_commands ~env config sys_packages |> List.map (fun ((`AsAdmin c | `AsUser c), a) -> c::a) @@ -1222,7 +1224,7 @@ let install_sys_packages ~map_sysmap ~confirm env config sys_packages t = and auto_install t sys_packages = try if OpamSysPoll.os_distribution env = Some "cygwin" then - OpamSysInteract.Cygwin.check_setup None; + OpamSysInteract.Cygwin.check_setup ~update:true; OpamSysInteract.install ~env config sys_packages; (* handles dry_run *) map_sysmap (fun _ -> OpamSysPkg.Set.empty) t with Failure msg -> diff --git a/src/state/opamSysInteract.ml b/src/state/opamSysInteract.ml index dd0478e4f24..c14b8f1eb26 100644 --- a/src/state/opamSysInteract.ml +++ b/src/state/opamSysInteract.ml @@ -454,22 +454,9 @@ module Cygwin = struct | `Cygwin -> root / "bin" (* Set setup.exe in the good place, ie in .opam/.cygwin/ *) - let check_setup setup = + let check_setup ~update = let dst = cygsetup () in - match setup with - | Some setup -> - log "Copying %s into %s" - (OpamFilename.to_string setup) - (OpamFilename.to_string dst); - let sha512 = - OpamHash.compute ~kind:`SHA512 (OpamFilename.to_string setup) - in - OpamFilename.copy ~src:setup ~dst; - let checksum_file = OpamFilename.add_extension dst "sha512" in - OpamFilename.remove checksum_file; - OpamFilename.with_open_out_bin checksum_file @@ fun c -> - output_string c (OpamHash.contents sha512) - | None -> + if update || not (OpamFilename.exists dst) then OpamProcess.Job.run @@ download_setupexe dst end @@ -1159,8 +1146,13 @@ let update ?(env=OpamVariable.Map.empty) config = in match cmd with | None -> + (* Cygwin doesn't have an update database per se, but one is supposed to use + the most current setup program when downloading setup.ini (which is the + package database (cf. the --no-version-check option). + Also, when #5839 is addressed, we'll need to cache setup.ini, and that + will want to be updated here too. *) if family = Cygwin then - Cygwin.check_setup None + Cygwin.check_setup ~update:true else OpamConsole.warning "Unknown update command for %s, skipping system update" diff --git a/src/state/opamSysInteract.mli b/src/state/opamSysInteract.mli index d9df5ba3b3b..9254c9a00f6 100644 --- a/src/state/opamSysInteract.mli +++ b/src/state/opamSysInteract.mli @@ -74,10 +74,11 @@ module Cygwin : sig (* Returns true if Cygwin install is internal *) val is_internal: OpamFile.Config.t -> bool - (* [check_setup path] checks and store Cygwin setup executable. Is [path] is - [None], it downloads it, otherwise it copies it to - /.cygwin/setup-x86_64.exe. *) - val check_setup: OpamFilename.t option -> unit + (* [check_setup ~update] downloads and stores a Cygwin setup executable to + /.cygwin/setup-x86_64.exe. If [~update = false], this only + happens if the setup executable does not already exist, otherwise it is. + updated. *) + val check_setup: update:bool -> unit (* Return Cygwin binary path *) val cygbin_opt: OpamFile.Config.t -> OpamFilename.Dir.t option