Skip to content

Commit 5c582e1

Browse files
authored
Merge pull request #5999 from kit-ty-kate/lock-stderr
Display lock hold/release messages on stderr instead of stdout
2 parents 1ff0770 + c9fe9f3 commit 5c582e1

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

master_changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ users)
1818
## Global CLI
1919
* Fix a typo in the variable description returned by "opam var" [#5961 @jmid]
2020
* Out-of-the-box UTF-8 paged --help on Windows [#5970 @kit-ty-kate]
21+
* ✘ Display lock hold/release messages on stderr instead of stdout [#5999 @kit-ty-kate - fix #5990]
2122

2223
## Plugins
2324

@@ -180,3 +181,4 @@ users)
180181
* `OpamStubs.getVersionInfo`: on Windows, retrives the version information block of an executable/library [#5963 @dra27]
181182
* `OpamStubs.readRegistry`: on Windows, complements `OpamStubs.writeRegistry` [#5963 @dra27]
182183
* `OpamStubs.get_initial_environment`: on Windows, returns the pristine environment for new shells [#5963 @dra27]
184+
* `OpamConsole`: Add `formatted_errmsg` [#5999 @kit-ty-kate]

src/core/opamConsole.ml

+7-5
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,13 @@ let note fmt =
610610
(OpamStd.Format.reformat ~start_column:7 ~indent:7 str)
611611
) fmt
612612

613+
let formatted_msg_aux ~indent out fmt =
614+
Printf.ksprintf
615+
(fun s -> print_message out "%s" (OpamStd.Format.reformat ?indent s))
616+
fmt
617+
613618
let errmsg fmt = print_message `stderr fmt
619+
let formatted_errmsg ?indent fmt = formatted_msg_aux ~indent `stderr fmt
614620

615621
let error_and_exit reason fmt =
616622
Printf.ksprintf (fun str ->
@@ -619,11 +625,7 @@ let error_and_exit reason fmt =
619625
) fmt
620626

621627
let msg fmt = print_message `stdout fmt
622-
623-
let formatted_msg ?indent fmt =
624-
Printf.ksprintf
625-
(fun s -> print_message `stdout "%s" (OpamStd.Format.reformat ?indent s))
626-
fmt
628+
let formatted_msg ?indent fmt = formatted_msg_aux ~indent `stdout fmt
627629

628630
let last_status = ref ""
629631

src/core/opamConsole.mli

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ val note : ('a, unit, string, unit) format4 -> 'a
9393
(** Message without prefix, reformat or newline, to stderr (useful to continue
9494
error messages without repeating "[ERROR]") *)
9595
val errmsg : ('a, unit, string, unit) format4 -> 'a
96+
val formatted_errmsg : ?indent:int -> ('a, unit, string, unit) format4 -> 'a
9697

9798
val error_and_exit :
9899
OpamStd.Sys.exit_reason -> ('a, unit, string, 'b) format4 -> 'a

src/core/opamSystem.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1224,15 +1224,15 @@ let rec flock_update
12241224
OpamConsole.error_and_exit `Locked
12251225
"Another process has locked %s and non blocking mode enabled"
12261226
file;
1227-
OpamConsole.formatted_msg
1227+
OpamConsole.formatted_errmsg
12281228
"Another process has locked %s, waiting (%s to abort)... "
12291229
file (if Sys.win32 then "CTRL+C" else "C-c");
12301230
let rec lock_w_ignore_sig () =
12311231
try Unix.lockf fd (unix_lock_op ~dontblock:false flag) 0;
1232-
with Sys.Break as e -> (OpamConsole.msg "\n"; raise e)
1232+
with Sys.Break as e -> (OpamConsole.errmsg "\n"; raise e)
12331233
| Unix.Unix_error (Unix.EINTR,_,_) -> lock_w_ignore_sig ()
12341234
in lock_w_ignore_sig ();
1235-
OpamConsole.msg "lock acquired.\n");
1235+
OpamConsole.errmsg "lock acquired.\n");
12361236
lock.kind <- (flag :> lock_flag)
12371237
| _ -> assert false
12381238

0 commit comments

Comments
 (0)