Skip to content

Commit

Permalink
set_file_perms: if the file is already executable, keep it executable
Browse files Browse the repository at this point in the history
Fixes: #1140
  • Loading branch information
RalfJung committed May 30, 2017
1 parent c26a45b commit 13d902a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/rustup-dist/src/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
Expand Down

0 comments on commit 13d902a

Please sign in to comment.