diff options
author | solach <46291346+solach@users.noreply.github.com> | 2023-07-20 13:51:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-20 19:51:02 +0000 |
commit | 5ff040bf59b1665f0545f9b6e732b027ab676446 (patch) | |
tree | b972f5dc477e1702ad345373453b9223d8e0ac2b /cli/tools/upgrade.rs | |
parent | 235fdc243faa6d0fc008dc7fa482c29e511c2fa0 (diff) |
fix(cli): output file handling in deno upgrade (#18994)
Diffstat (limited to 'cli/tools/upgrade.rs')
-rw-r--r-- | cli/tools/upgrade.rs | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 78ac59981..f37ee8455 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -270,25 +270,31 @@ pub async fn upgrade( let factory = CliFactory::from_flags(flags).await?; let client = factory.http_client(); let current_exe_path = std::env::current_exe()?; - let metadata = fs::metadata(¤t_exe_path)?; - let permissions = metadata.permissions(); - - if permissions.readonly() { - bail!( - "You do not have write permission to {}", - current_exe_path.display() - ); - } - #[cfg(unix)] - if std::os::unix::fs::MetadataExt::uid(&metadata) == 0 - && !nix::unistd::Uid::effective().is_root() - { - bail!(concat!( - "You don't have write permission to {} because it's owned by root.\n", - "Consider updating deno through your package manager if its installed from it.\n", - "Otherwise run `deno upgrade` as root.", - ), current_exe_path.display()); - } + let output_exe_path = + upgrade_flags.output.as_ref().unwrap_or(¤t_exe_path); + + let permissions = if let Ok(metadata) = fs::metadata(output_exe_path) { + let permissions = metadata.permissions(); + if permissions.readonly() { + bail!( + "You do not have write permission to {}", + output_exe_path.display() + ); + } + #[cfg(unix)] + if std::os::unix::fs::MetadataExt::uid(&metadata) == 0 + && !nix::unistd::Uid::effective().is_root() + { + bail!(concat!( + "You don't have write permission to {} because it's owned by root.\n", + "Consider updating deno through your package manager if its installed from it.\n", + "Otherwise run `deno upgrade` as root.", + ), output_exe_path.display()); + } + permissions + } else { + fs::metadata(¤t_exe_path)?.permissions() + }; let install_version = match upgrade_flags.version { Some(passed_version) => { |