Skip to content

Commit 61f42f4

Browse files
committed
interpret relative paths relative to '.'
1 parent 84bc552 commit 61f42f4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/common/context.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl Context {
107107

108108
#[cfg(feature = "sudoedit")]
109109
pub fn from_edit_opts(sudo_options: SudoEditOptions) -> Result<Context, Error> {
110+
use std::path::Path;
110111
let hostname = Hostname::resolve();
111112
let current_user = CurrentUser::resolve()?;
112113

@@ -115,9 +116,16 @@ impl Context {
115116

116117
// resolve file arguments; if something can't be resolved, don't add it to the "edit" list
117118
let resolved_args = sudo_options.positional_args.iter().map(|arg| {
118-
crate::common::resolve::canonicalize_newfile(arg)
119-
.map_err(|_| arg)
120-
.and_then(|path| path.into_os_string().into_string().map_err(|_| arg))
119+
let path = Path::new(arg);
120+
let absolute_path;
121+
crate::common::resolve::canonicalize_newfile(if path.is_absolute() {
122+
path
123+
} else {
124+
absolute_path = Path::new(".").join(path);
125+
&absolute_path
126+
})
127+
.map_err(|_| arg)
128+
.and_then(|path| path.into_os_string().into_string().map_err(|_| arg))
121129
});
122130

123131
let files_to_edit = resolved_args

0 commit comments

Comments
 (0)