diff options
author | sigmaSd <bedisnbiba@gmail.com> | 2022-10-21 20:50:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 15:50:03 -0400 |
commit | 8c9e6c5565c1c00437d083de76cdd944e44b1d99 (patch) | |
tree | a6630fa3c29651e280f38d18825400dd8a299ec0 | |
parent | b3ddd0cea268414e1a00951f24d4767ed6eafd75 (diff) |
feat(upgrade): check if user has write access to deno exe (#16378)
-rw-r--r-- | cli/Cargo.toml | 6 | ||||
-rw-r--r-- | cli/tools/upgrade.rs | 18 |
2 files changed, 19 insertions, 5 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c22de3dbd..d1a7ab318 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -118,6 +118,9 @@ fwdansi = "=1.1.0" junction = "=0.2.0" winapi = { version = "=0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] } +[target.'cfg(unix)'.dependencies] +nix = "=0.24.2" + [dev-dependencies] deno_bench_util = { version = "0.67.0", path = "../bench_util" } dotenv = "=0.15.0" @@ -129,9 +132,6 @@ test_util = { path = "../test_util" } trust-dns-client = "=0.22.0" trust-dns-server = "=0.22.0" -[target.'cfg(unix)'.dev-dependencies] -nix = "=0.24.2" - [package.metadata.winres] # This section defines the metadata that appears in the deno.exe PE header. OriginalFilename = "deno.exe" diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 8adb102aa..b80b8091c 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -128,10 +128,24 @@ pub fn check_for_upgrades(cache_dir: PathBuf) { pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> { let old_exe_path = std::env::current_exe()?; - let permissions = fs::metadata(&old_exe_path)?.permissions(); + let metadata = fs::metadata(&old_exe_path)?; + let permissions = metadata.permissions(); if permissions.readonly() { - bail!("You do not have write permission to {:?}", old_exe_path); + bail!( + "You do not have write permission to {}", + old_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.", + ), old_exe_path.display()); } let client = build_http_client(upgrade_flags.ca_file)?; |