summaryrefslogtreecommitdiff
path: root/src/pkgtoolkit/install.rs
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-12-09 17:54:00 +0300
committerNamilskyy <alive6863@gmail.com>2025-12-09 17:54:00 +0300
commit1c3b561fa8d7a370651c77f6b8e22c8aa9c8d9f1 (patch)
tree37e1e44d027e93234ca16162bc3611557ed8ce05 /src/pkgtoolkit/install.rs
parentb55537c7d2652d1f5b389cce503cc176d1f970ec (diff)
Fix multibinary installing
Diffstat (limited to 'src/pkgtoolkit/install.rs')
-rw-r--r--src/pkgtoolkit/install.rs121
1 files changed, 75 insertions, 46 deletions
diff --git a/src/pkgtoolkit/install.rs b/src/pkgtoolkit/install.rs
index 37155c2..4eeff2f 100644
--- a/src/pkgtoolkit/install.rs
+++ b/src/pkgtoolkit/install.rs
@@ -88,18 +88,26 @@ impl InstallOperations for Package {
)));
}
- let staging_dir = Path::new(&config.paths.cache_dir).join("staging");
- create_dir_all(&staging_dir)?;
- all_files = Self::collect_files_from_dir(&staging_dir, &staging_dir)?
+ let build_dir =
+ Path::new(&config.paths.cache_dir).join(format!("{}-{}", self.name, self.version));
+ let target_release = build_dir.join("target/release");
+
+ if !target_release.exists() {
+ return Err(std::io::Error::other(format!(
+ "target/release directory not found: {}",
+ target_release.display()
+ )));
+ }
+
+ all_files = Self::collect_files_from_dir(&target_release, &target_release)?
.iter()
- .map(|rel| format!("/{}", rel)) // Преобразуйте в абсолютные пути (предполагаем root=/)
+ .map(|rel| format!("/{}", rel))
.collect();
for file in &all_files {
- let src = staging_dir.join(file.trim_start_matches('/'));
- let dest = Path::new(file);
+ let src = target_release.join(file.trim_start_matches('/'));
+ let dest = Path::new(&install_meta.install.path).join(file.trim_start_matches('/'));
- // Check if source file exists
if !src.exists() {
log::warn!("Source file not found: {:?}, skipping", src);
continue;
@@ -109,7 +117,7 @@ impl InstallOperations for Package {
create_dir_all(parent)?;
}
- fs::copy(&src, dest).map_err(|e| {
+ fs::copy(&src, &dest).map_err(|e| {
std::io::Error::other(format!(
"Failed to copy {} to {}: {}",
src.display(),
@@ -117,16 +125,45 @@ impl InstallOperations for Package {
e
))
})?;
- // TODO: Set proper permissions
- }
- fs::remove_dir_all(&staging_dir)?;
+ // Set permissions
+ let mode = u32::from_str_radix(&install_meta.install.mode, 8).map_err(|_| {
+ std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ "Invalid mode string in INSTALL",
+ )
+ })?;
+ let perms = Permissions::from_mode(mode);
+ set_permissions(&dest, perms).map_err(|e| {
+ std::io::Error::other(format!(
+ "Failed to set permissions for {}: {}",
+ dest.display(),
+ e
+ ))
+ })?;
+
+ let output = Command::new("chown")
+ .arg(format!(
+ "{}:{}",
+ install_meta.install.user, install_meta.install.group
+ ))
+ .arg(&dest)
+ .output()
+ .map_err(|e| std::io::Error::other(format!("'chown' command failed: {}", e)))?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ log::warn!(
+ "Warning: 'chown' command failed for {} (requires root?):\n{}",
+ dest.display(),
+ stderr
+ );
+ }
+ }
} else {
log::info!(
"No BUILD file or it's empty. Treating as binary package. Installing via INSTALL config or custom script."
);
-
- // Validate custom script before execution
if let Some(ref script) = install_meta.install.custom_script {
Self::validate_custom_script(script)?;
}
@@ -169,10 +206,8 @@ impl InstallOperations for Package {
dest_path.to_string_lossy().ends_with('/')
);
- // Check if dest_path is a directory, if so, copy all executables from target/release
if dest_path.is_dir() || dest_path.to_string_lossy().ends_with('/') {
log::info!("Taking multi-binary package path");
- // Multi-binary package - copy all executables from target/release
let target_release = build_dir.join("target/release");
if !target_release.exists() {
return Err(std::io::Error::other(format!(
@@ -181,7 +216,6 @@ impl InstallOperations for Package {
)));
}
- // Create destination directory if it doesn't exist
create_dir_all(dest_path).map_err(|e| {
std::io::Error::other(format!("Failed to create dest dir: {}", e))
})?;
@@ -191,41 +225,36 @@ impl InstallOperations for Package {
let entry = entry?;
let path = entry.path();
- // Check if it's an executable file
- if path.is_file()
- && let Ok(metadata) = fs::metadata(&path) {
- let mode = metadata.permissions().mode();
+ if path.is_file()
+ && let Ok(metadata) = fs::metadata(&path)
+ {
+ let mode = metadata.permissions().mode();
+ log::debug!("Checking file: {:?}, mode: {:o}", path.file_name(), mode);
+ if mode & 0o111 != 0 {
+ let file_name = path.file_name().unwrap().to_string_lossy();
+ let dest_file = dest_path.join(&*file_name);
+
+ log::info!(
+ "Copying executable: {} to {}",
+ file_name,
+ dest_file.display()
+ );
+ fs::copy(&path, &dest_file).map_err(|e| {
+ std::io::Error::other(format!(
+ "Failed to copy {}: {}",
+ file_name, e
+ ))
+ })?;
+
+ copied_files.push(dest_file);
+ } else {
log::debug!(
- "Checking file: {:?}, mode: {:o}",
+ "File {:?} is not executable (mode: {:o})",
path.file_name(),
mode
);
- if mode & 0o111 != 0 {
- let file_name = path.file_name().unwrap().to_string_lossy();
- let dest_file = dest_path.join(&*file_name);
-
- log::info!(
- "Copying executable: {} to {}",
- file_name,
- dest_file.display()
- );
- fs::copy(&path, &dest_file).map_err(|e| {
- std::io::Error::other(format!(
- "Failed to copy {}: {}",
- file_name, e
- ))
- })?;
-
- copied_files.push(dest_file);
- } else {
- log::debug!(
- "File {:?} is not executable (mode: {:o})",
- path.file_name(),
- mode
- );
- }
}
-
+ }
}
if copied_files.is_empty() {