1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(cli): output file handling in deno upgrade (#18994)

This commit is contained in:
solach 2023-07-20 13:51:02 -06:00 committed by GitHub
parent 235fdc243f
commit 5ff040bf59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -270,25 +270,31 @@ pub async fn upgrade(
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags).await?;
let client = factory.http_client(); let client = factory.http_client();
let current_exe_path = std::env::current_exe()?; let current_exe_path = std::env::current_exe()?;
let metadata = fs::metadata(&current_exe_path)?; let output_exe_path =
let permissions = metadata.permissions(); upgrade_flags.output.as_ref().unwrap_or(&current_exe_path);
if permissions.readonly() { let permissions = if let Ok(metadata) = fs::metadata(output_exe_path) {
bail!( let permissions = metadata.permissions();
"You do not have write permission to {}", if permissions.readonly() {
current_exe_path.display() 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() #[cfg(unix)]
{ if std::os::unix::fs::MetadataExt::uid(&metadata) == 0
bail!(concat!( && !nix::unistd::Uid::effective().is_root()
"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", bail!(concat!(
"Otherwise run `deno upgrade` as root.", "You don't have write permission to {} because it's owned by root.\n",
), current_exe_path.display()); "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(&current_exe_path)?.permissions()
};
let install_version = match upgrade_flags.version { let install_version = match upgrade_flags.version {
Some(passed_version) => { Some(passed_version) => {