Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark executables as executable on Unix #14

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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