From ace828731e36a72a8e0cbc14a9757be056c811d1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 21 Aug 2014 09:24:34 -0700 Subject: [PATCH] Rename `cargo-update` to `cargo-updat` Any executable with the substring "update" on windows is subject to requiring privilege escalation. For now we just rename the actual executable to `cargo-updat` but rename all usage of it so that it's not actually visible. Closes #393 --- Cargo.toml | 5 ++++- src/bin/{cargo-update.rs => cargo-updat.rs} | 0 src/bin/cargo.rs | 13 ++++++++++--- tests/test_cargo_compile_git_deps.rs | 12 ++++++------ 4 files changed, 20 insertions(+), 10 deletions(-) rename src/bin/{cargo-update.rs => cargo-updat.rs} (100%) diff --git a/Cargo.toml b/Cargo.toml index 750e923ea7c..df9a4b69b78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,8 +97,11 @@ name = "cargo-generate-lockfile" test = false doc = false +# Note that this is named `updat`, not `update`, this is sadly because windows +# will require elevated privileges for any executable with the string "update" +# in its name. [[bin]] -name = "cargo-update" +name = "cargo-updat" test = false doc = false diff --git a/src/bin/cargo-update.rs b/src/bin/cargo-updat.rs similarity index 100% rename from src/bin/cargo-update.rs rename to src/bin/cargo-updat.rs diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index a5fa3ec1664..2b0c0644397 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -60,12 +60,17 @@ fn execute(flags: Flags, shell: &mut MultiShell) -> CliResult> { shell.set_verbose(flags.flag_verbose); if flags.flag_list { println!("Installed Commands:"); - for command in list_commands().iter() { + for command in list_commands().move_iter() { + let command = if command.as_slice() == "updat" { + "update".to_string() + } else { + command + }; println!(" {}", command); - // TODO: it might be helpful to add result of -h to each command. }; return Ok(None) } + let mut args = flags.arg_args.clone(); args.insert(0, flags.arg_command.clone()); match flags.arg_command.as_slice() { @@ -109,7 +114,8 @@ fn execute(flags: Flags, shell: &mut MultiShell) -> CliResult> { Ok(None) } -fn execute_subcommand(cmd: &str, is_help: bool, flags: &Flags, shell: &mut MultiShell) -> () { +fn execute_subcommand(cmd: &str, is_help: bool, flags: &Flags, + shell: &mut MultiShell) -> () { match find_command(cmd) { Some(command) => { let mut command = Command::new(command); @@ -183,6 +189,7 @@ fn is_executable(path: &Path) -> bool { /// Get `Command` to run given command. fn find_command(cmd: &str) -> Option { + let cmd = if cmd == "update" {"updat"} else {cmd}; let command_exe = format!("cargo-{}{}", cmd, os::consts::EXE_SUFFIX); let dirs = list_command_directory(); let mut command_paths = dirs.iter().map(|dir| dir.join(command_exe.as_slice())); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 5e337b37e34..1605477eb02 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -548,7 +548,7 @@ test!(recompilation { FRESH, git_project.url(), FRESH, p.url()))); - assert_that(p.process(cargo_dir().join("cargo-update")), + assert_that(p.process(cargo_dir().join("cargo")).arg("update"), execs().with_stdout(format!("{} git repository `{}`", UPDATING, git_project.url()))); @@ -574,7 +574,7 @@ test!(recompilation { p.root().move_into_the_past().assert(); // Update the dependency and carry on! - assert_that(p.process(cargo_dir().join("cargo-update")), + assert_that(p.process(cargo_dir().join("cargo")).arg("update"), execs().with_stdout(format!("{} git repository `{}`", UPDATING, git_project.url()))); @@ -665,7 +665,7 @@ test!(update_with_shared_deps { timer::sleep(Duration::milliseconds(1000)); - assert_that(p.process(cargo_dir().join("cargo-update")).arg("dep1"), + assert_that(p.process(cargo_dir().join("cargo")).arg("update").arg("dep1"), execs().with_stdout(format!("{} git repository `{}`", UPDATING, git_project.url()))); @@ -681,7 +681,7 @@ test!(update_with_shared_deps { compiling = COMPILING, dir = p.url()))); // We should be able to update transitive deps - assert_that(p.process(cargo_dir().join("cargo-update")).arg("bar"), + assert_that(p.process(cargo_dir().join("cargo")).arg("update").arg("bar"), execs().with_stdout(format!("{} git repository `{}`", UPDATING, git_project.url()))); @@ -789,7 +789,7 @@ test!(two_deps_only_update_one { git1.process("git").args(["commit", "-m", "test"]).exec_with_output() .assert(); - assert_that(project.process(cargo_dir().join("cargo-update")).arg("dep1"), + assert_that(project.process(cargo_dir().join("cargo")).arg("update").arg("dep1"), execs() .with_stdout(format!("{} git repository `{}`\n", UPDATING, git1.url())) @@ -939,7 +939,7 @@ test!(dep_with_changed_submodule { timer::sleep(Duration::milliseconds(1000)); // Update the dependency and carry on! - assert_that(project.process(cargo_dir().join("cargo-update")), execs() + assert_that(project.process(cargo_dir().join("cargo")).arg("update"), execs() .with_stderr("") .with_stdout(format!("{} git repository `{}`", UPDATING,