From 13d902a319cd76bc4898f56119849ee94b7425aa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 30 May 2017 13:04:05 -0700 Subject: [PATCH] set_file_perms: if the file is already executable, keep it executable Fixes: #1140 --- src/rustup-dist/src/component/package.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/rustup-dist/src/component/package.rs b/src/rustup-dist/src/component/package.rs index 3326231ab0a..a5d396d2baf 100644 --- a/src/rustup-dist/src/component/package.rs +++ b/src/rustup-dist/src/component/package.rs @@ -127,8 +127,11 @@ fn set_file_perms(dest_path: &Path, src_path: &Path) -> Result<()> { use std::os::unix::fs::PermissionsExt; use walkdir::WalkDir; - // By convention, anything in the bin/ directory of the package is a binary - let is_bin = if let Some(p) = src_path.parent() { + let mut perm = try!(fs::metadata(dest_path).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)) + .permissions(); + + // By convention, anything that is rwx by the user and anything in the bin/ directory of the package is a binary + let is_bin = perm.mode() & 0o700 == 0o700 || if let Some(p) = src_path.parent() { p.ends_with("bin") } else { false @@ -152,13 +155,9 @@ fn set_file_perms(dest_path: &Path, src_path: &Path) -> Result<()> { } } } else if is_bin { - let mut perm = try!(fs::metadata(dest_path).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)) - .permissions(); perm.set_mode(0o755); try!(fs::set_permissions(dest_path, perm).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)); } else { - let mut perm = try!(fs::metadata(dest_path).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)) - .permissions(); perm.set_mode(0o644); try!(fs::set_permissions(dest_path, perm).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)); }