rust-chg: move get_umask() call out of run() function
authorYuya Nishihara <yuya@tcha.org>
Sat, 11 Apr 2020 15:27:08 +0900
changeset 44694 5ac5c25ea97b
parent 44693 61fda2dbc522
child 44695 f87804825df5
rust-chg: move get_umask() call out of run() function run() will be an async function, but get_umask() isn't thread safe. Differential Revision: https://phab.mercurial-scm.org/D8402
rust/chg/src/main.rs
--- a/rust/chg/src/main.rs	Sat Apr 11 00:21:37 2020 +0900
+++ b/rust/chg/src/main.rs	Sat Apr 11 15:27:08 2020 +0900
@@ -59,15 +59,15 @@
 
     // TODO: add loop detection by $CHGINTERNALMARK
 
-    let code = run().unwrap_or_else(|err| {
+    let umask = unsafe { procutil::get_umask() }; // not thread safe
+    let code = run(umask).unwrap_or_else(|err| {
         writeln!(io::stderr(), "chg: abort: {}", err).unwrap_or(());
         255
     });
     process::exit(code);
 }
 
-fn run() -> io::Result<i32> {
-    let umask = unsafe { procutil::get_umask() }; // not thread safe
+fn run(umask: u32) -> io::Result<i32> {
     let mut loc = Locator::prepare_from_env()?;
     loc.set_early_args(locator::collect_early_args(env::args_os().skip(1)));
     let handler = ChgUiHandler::new();