From c9fe9f306534386ceb15b8cd5572b9e6013f57a0 Mon Sep 17 00:00:00 2001 From: Kate Date: Thu, 6 Jun 2024 09:54:59 +0100 Subject: [PATCH] Display lock hold/release messages on stderr instead of stdout --- master_changes.md | 2 ++ src/core/opamConsole.ml | 12 +++++++----- src/core/opamConsole.mli | 1 + src/core/opamSystem.ml | 6 +++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/master_changes.md b/master_changes.md index 8f559742d8a..702f6274bfb 100644 --- a/master_changes.md +++ b/master_changes.md @@ -18,6 +18,7 @@ users) ## Global CLI * Fix a typo in the variable description returned by "opam var" [#5961 @jmid] * Out-of-the-box UTF-8 paged --help on Windows [#5970 @kit-ty-kate] + * ✘ Display lock hold/release messages on stderr instead of stdout [#5999 @kit-ty-kate - fix #5990] ## Plugins @@ -176,3 +177,4 @@ users) * `OpamStubs.getVersionInfo`: on Windows, retrives the version information block of an executable/library [#5963 @dra27] * `OpamStubs.readRegistry`: on Windows, complements `OpamStubs.writeRegistry` [#5963 @dra27] * `OpamStubs.get_initial_environment`: on Windows, returns the pristine environment for new shells [#5963 @dra27] + * `OpamConsole`: Add `formatted_errmsg` [#5999 @kit-ty-kate] diff --git a/src/core/opamConsole.ml b/src/core/opamConsole.ml index 2e993f3d8c6..bfc434c6df0 100644 --- a/src/core/opamConsole.ml +++ b/src/core/opamConsole.ml @@ -610,7 +610,13 @@ let note fmt = (OpamStd.Format.reformat ~start_column:7 ~indent:7 str) ) fmt +let formatted_msg_aux ~indent out fmt = + Printf.ksprintf + (fun s -> print_message out "%s" (OpamStd.Format.reformat ?indent s)) + fmt + let errmsg fmt = print_message `stderr fmt +let formatted_errmsg ?indent fmt = formatted_msg_aux ~indent `stderr fmt let error_and_exit reason fmt = Printf.ksprintf (fun str -> @@ -619,11 +625,7 @@ let error_and_exit reason fmt = ) fmt let msg fmt = print_message `stdout fmt - -let formatted_msg ?indent fmt = - Printf.ksprintf - (fun s -> print_message `stdout "%s" (OpamStd.Format.reformat ?indent s)) - fmt +let formatted_msg ?indent fmt = formatted_msg_aux ~indent `stdout fmt let last_status = ref "" diff --git a/src/core/opamConsole.mli b/src/core/opamConsole.mli index c82fae1bbf4..5244b4a00f2 100644 --- a/src/core/opamConsole.mli +++ b/src/core/opamConsole.mli @@ -93,6 +93,7 @@ val note : ('a, unit, string, unit) format4 -> 'a (** Message without prefix, reformat or newline, to stderr (useful to continue error messages without repeating "[ERROR]") *) val errmsg : ('a, unit, string, unit) format4 -> 'a +val formatted_errmsg : ?indent:int -> ('a, unit, string, unit) format4 -> 'a val error_and_exit : OpamStd.Sys.exit_reason -> ('a, unit, string, 'b) format4 -> 'a diff --git a/src/core/opamSystem.ml b/src/core/opamSystem.ml index 1282e307094..925a232469a 100644 --- a/src/core/opamSystem.ml +++ b/src/core/opamSystem.ml @@ -1224,15 +1224,15 @@ let rec flock_update OpamConsole.error_and_exit `Locked "Another process has locked %s and non blocking mode enabled" file; - OpamConsole.formatted_msg + OpamConsole.formatted_errmsg "Another process has locked %s, waiting (%s to abort)... " file (if Sys.win32 then "CTRL+C" else "C-c"); let rec lock_w_ignore_sig () = try Unix.lockf fd (unix_lock_op ~dontblock:false flag) 0; - with Sys.Break as e -> (OpamConsole.msg "\n"; raise e) + with Sys.Break as e -> (OpamConsole.errmsg "\n"; raise e) | Unix.Unix_error (Unix.EINTR,_,_) -> lock_w_ignore_sig () in lock_w_ignore_sig (); - OpamConsole.msg "lock acquired.\n"); + OpamConsole.errmsg "lock acquired.\n"); lock.kind <- (flag :> lock_flag) | _ -> assert false