Skip to content

Commit d98ef8e

Browse files
committed
Assigning exec perms to the created AppImage
1 parent a9c2b6a commit d98ef8e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/targets.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs;
1+
use std::fs::{self, Permissions};
22
use std::io::{BufReader, Read, Write};
33
use std::path::{Path, PathBuf};
44

@@ -8,7 +8,7 @@ use image::{GenericImageView, ImageFormat, ImageReader};
88
use crate::actions::{Archiver, CommandRunner, Extractor};
99
use crate::config::Config;
1010
use crate::{actions, appimage, config, console, files};
11-
use crate::console::{exit_err, print_note, print_significant, print_step, print_step_verbose, print_success, print_warn};
11+
use crate::console::{exit_err, print_note, print_significant, print_step, print_step_verbose, print_success, print_warn, CommandLineSettings};
1212
use crate::deps::Dependency;
1313
use crate::project_config::{self, Package};
1414
use crate::deps;
@@ -440,6 +440,26 @@ fn build_linux() {
440440

441441
print_step("Embedding created SquashFS into the AppImage");
442442
appimage::embed_squashfs(&app_img, &new_squashfs);
443+
444+
#[cfg(target_family = "unix")]
445+
apply_exec_perms(&cmd_conf, &app_img).unwrap_or_else(|err| {
446+
print_warn(format!("Failed to assign executable permission: {}", err));
447+
});
448+
}
449+
450+
#[cfg(target_family = "unix")]
451+
fn apply_exec_perms(cmd_conf: &CommandLineSettings, exe: &PathBuf) -> Result<(), String> {
452+
use std::os::unix::fs::PermissionsExt;
453+
454+
print_step_verbose(&cmd_conf, "Assigning exec permissions");
455+
456+
let meta = fs::metadata(&exe).map_err(|err| err.to_string())?;
457+
let mut perms = meta.permissions();
458+
perms.set_mode(perms.mode() | 0o755);
459+
460+
fs::set_permissions(&exe, perms).map_err(|err| err.to_string())?;
461+
462+
Ok(())
443463
}
444464

445465
fn build_win64() {

0 commit comments

Comments
 (0)