Skip to content

Commit 96c6ad1

Browse files
committed
rewrite user_error/info/warn to conform to the syntax supported by xlat!
this is a more restricted, subset of what format_args accepts; if in the future we get clippy lints about this, we should be prepared to silence them
1 parent 3c577c7 commit 96c6ad1

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

src/exec/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ pub fn run_command(
137137
unsafe {
138138
command.pre_exec(move || {
139139
if let Err(err) = env::set_current_dir(&path) {
140-
user_error!("unable to change directory to {}: {}", path.display(), err);
140+
user_error!(
141+
"unable to change directory to {path}: {error}",
142+
path = path.display(),
143+
error = err
144+
);
141145
if is_chdir {
142146
return Err(err);
143147
}

src/su/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ impl SuContext {
144144
// taken into account, unless su is called by root.
145145
if is_restricted(user_shell.as_path()) && !is_current_root {
146146
user_warn!(
147-
"using restricted shell {}",
148-
user_shell.as_os_str().to_string_lossy()
147+
"using restricted shell {path}",
148+
path = user_shell.as_os_str().to_string_lossy()
149149
);
150150
command = user_shell;
151151
}

src/sudo/cli/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ impl SudoOptions {
676676
}
677677
"-E" | "--preserve-env" => {
678678
user_warn!(
679-
"preserving the entire environment is not supported, `{flag}` is ignored"
679+
"preserving the entire environment is not supported, '{flag}' is ignored",
680+
flag = flag
680681
)
681682
}
682683
"-e" | "--edit" if !invoked_as_sudoedit => {

src/sudo/edit.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub(super) fn edit_files(
142142
let data = file.new_data.expect("filled in above");
143143
if data == file.old_data {
144144
// File unchanged. No need to write it again.
145-
user_info!("{} unchanged", file.path.display());
145+
user_info!("{path} unchanged", path = file.path.display());
146146
continue;
147147
}
148148

@@ -181,8 +181,9 @@ impl Drop for TempDirDropGuard {
181181
fn drop(&mut self) {
182182
if let Err(e) = std::fs::remove_dir_all(&self.0) {
183183
user_error!(
184-
"failed to remove temporary directory {}: {e}",
185-
self.0.display(),
184+
"failed to remove temporary directory {path}: {error}",
185+
path = self.0.display(),
186+
error = e
186187
);
187188
};
188189
}
@@ -192,7 +193,7 @@ fn handle_child(editor: &Path, file: Vec<ChildFileInfo<'_>>) -> ! {
192193
match handle_child_inner(editor, file) {
193194
Ok(()) => process::exit(0),
194195
Err(err) => {
195-
user_error!("{err}");
196+
user_error!("{error}", error = err);
196197
process::exit(1);
197198
}
198199
}
@@ -308,7 +309,7 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
308309
) {
309310
Ok(b'y') => {}
310311
_ => {
311-
user_info!("not overwriting {}", file.path.display());
312+
user_info!("not overwriting {path}", path = file.path.display());
312313

313314
// Parent ignores write when new data matches old data
314315
write_stream(&mut file.new_data_tx, &file.old_data)

src/sudo/pipeline/edit.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ pub fn run_edit(edit_opts: SudoEditOptions) -> Result<(), Error> {
3434
Ok(file) => opened_files.push((path, file)),
3535
// ErrorKind::FilesystemLoop was only stabilized in 1.83
3636
Err(error) if error.raw_os_error() == Some(libc::ELOOP) => {
37-
user_error!("{arg}: editing symbolic links is not permitted")
37+
user_error!(
38+
"{path}: editing symbolic links is not permitted",
39+
path = arg
40+
)
41+
}
42+
Err(error) => {
43+
user_error!("error opening {path}: {error}", path = arg, error = error)
3844
}
39-
Err(error) => user_error!("error opening {arg}: {error}"),
4045
}
4146
} else {
42-
user_error!("invalid path: {arg}");
47+
user_error!("invalid path: {path}", path = arg);
4348
}
4449
}
4550

0 commit comments

Comments
 (0)