Skip to content

Commit

Permalink
Mark executables as executable on Unix (#14)
Browse files Browse the repository at this point in the history
* Mark executables as executable on Unix

* Update changelog
  • Loading branch information
LPGhatguy committed May 24, 2022
1 parent e5d9911 commit b936ce9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Aftman Changelog

## Unreleased Changes
* Aftman now correctly marks executables as executable on Unix platforms. ([#14])

[#14]: https://github.com/LPGhatguy/aftman/pull/14

## [0.2.2] (May 23, 2022)
* Fixed building on non-Windows platforms
Expand Down
33 changes: 23 additions & 10 deletions src/tool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,27 @@ impl ToolStorage {
Ok(())
}

fn install_executable(&self, id: &ToolId, mut contents: impl Read) -> anyhow::Result<()> {
let output_path = self.exe_path(id);

fs_err::create_dir_all(output_path.parent().unwrap())?;

let mut output = BufWriter::new(File::create(&output_path)?);
io::copy(&mut contents, &mut output)?;
output.flush()?;

#[cfg(unix)]
{
use std::fs::{set_permissions, Permissions};
use std::os::unix::fs::PermissionsExt;

set_permissions(&output_path, Permissions::from_mode(0o755))
.context("failed to mark executable as executable")?;
}

Ok(())
}

fn install_artifact(&self, id: &ToolId, artifact: impl Read + Seek) -> anyhow::Result<()> {
let output_path = self.exe_path(id);
let expected_name = format!("{}{EXE_SUFFIX}", id.name().name());
Expand All @@ -333,11 +354,7 @@ impl ToolStorage {

if file.name() == expected_name {
log::debug!("Installing file {} from archive...", file.name());

let mut output = BufWriter::new(File::create(&output_path)?);
io::copy(&mut file, &mut output)?;
output.flush()?;

self.install_executable(id, &mut file)?;
return Ok(());
}
}
Expand All @@ -349,11 +366,7 @@ impl ToolStorage {

if file.name().ends_with(EXE_SUFFIX) {
log::debug!("Installing file {} from archive...", file.name());

let mut output = BufWriter::new(File::create(&output_path)?);
io::copy(&mut file, &mut output)?;
output.flush()?;

self.install_executable(id, &mut file)?;
return Ok(());
}
}
Expand Down

0 comments on commit b936ce9

Please sign in to comment.