1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-07 06:46:59 -05:00

fix(cli): deno upgrade file permission (#18427)

This commit is contained in:
滑威 2023-03-26 17:19:12 +08:00 committed by Matt Mastracci
parent d676944536
commit 7fa2bf34eb

View file

@ -265,13 +265,15 @@ pub async fn upgrade(
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::build(flags).await?;
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 =
upgrade_flags.output.as_ref().unwrap_or(&current_exe_path);
let metadata = fs::metadata(output_exe_path)?;
let permissions = metadata.permissions(); let permissions = metadata.permissions();
if permissions.readonly() { if permissions.readonly() {
bail!( bail!(
"You do not have write permission to {}", "You do not have write permission to {}",
current_exe_path.display() output_exe_path.display()
); );
} }
#[cfg(unix)] #[cfg(unix)]
@ -282,7 +284,7 @@ pub async fn upgrade(
"You don't have write permission to {} because it's owned by root.\n", "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", "Consider updating deno through your package manager if its installed from it.\n",
"Otherwise run `deno upgrade` as root.", "Otherwise run `deno upgrade` as root.",
), current_exe_path.display()); ), output_exe_path.display());
} }
let client = &ps.http_client; let client = &ps.http_client;