Skip to content

Commit

Permalink
Rename cargo-update to cargo-updat
Browse files Browse the repository at this point in the history
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 rust-lang#393
  • Loading branch information
alexcrichton committed Aug 21, 2014
1 parent 5a4247e commit ace8287
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
13 changes: 10 additions & 3 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ fn execute(flags: Flags, shell: &mut MultiShell) -> CliResult<Option<()>> {
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() {
Expand Down Expand Up @@ -109,7 +114,8 @@ fn execute(flags: Flags, shell: &mut MultiShell) -> CliResult<Option<()>> {
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);
Expand Down Expand Up @@ -183,6 +189,7 @@ fn is_executable(path: &Path) -> bool {

/// Get `Command` to run given command.
fn find_command(cmd: &str) -> Option<Path> {
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()));
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cargo_compile_git_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand All @@ -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())));
Expand Down Expand Up @@ -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())));
Expand All @@ -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())));
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ace8287

Please sign in to comment.