From e6773144dbccf706c5d404e34eaacdc664c94333 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Sun, 13 Oct 2024 13:57:55 +0200 Subject: [PATCH] fix: allow writes to copied cas files --- CHANGELOG.md | 1 + src/source/fs.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 969eb90..124ec26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Correct `pesde.toml` inclusion message in `publish` command by @daimond113 +- Allow writes to files when `link` is false in PackageFS::write_to by @daimond113 ## [0.5.0-rc.5] - 2024-10-12 ### Added diff --git a/src/source/fs.rs b/src/source/fs.rs index 6b04a0d..77f8aa4 100644 --- a/src/source/fs.rs +++ b/src/source/fs.rs @@ -160,7 +160,21 @@ impl PackageFS { if link { std::fs::hard_link(cas_file_path, path)?; } else { - std::fs::copy(cas_file_path, path)?; + let mut f = std::fs::File::create(&path)?; + f.write_all(&std::fs::read(cas_file_path)?)?; + + let mut permissions = f.metadata()?.permissions(); + #[cfg(windows)] + { + #[allow(clippy::permissions_set_readonly_false)] + permissions.set_readonly(false); + } + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + permissions.set_mode(permissions.mode() | 0o644); + } + f.set_permissions(permissions)?; } } FSEntry::Directory => {