Skip to content

Commit

Permalink
feat: Make config file executable
Browse files Browse the repository at this point in the history
  • Loading branch information
lj3954 committed Aug 9, 2024
1 parent ea55303 commit 1205d22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion quickget/core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{
fs::File,
io::Write,
num::NonZeroUsize,
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
process::Command,
};
Expand Down Expand Up @@ -305,8 +306,23 @@ impl QuickgetInstance {
..Default::default()
};
let mut config_file = File::create(&self.config_file_path)?;

let shebang = which::which("quickemu-rs")
.ok()
.or_else(|| {
std::env::current_exe()
.ok()
.map(|path| path.with_file_name("quickemu-rs"))
.filter(|path| path.exists())
})
.map(|path| format!("#!{} --vm\n", path.to_string_lossy()));

if shebang.is_some() {
let _ = config_file.set_permissions(PermissionsExt::from_mode(0o755));
}

let serialized_config = toml::to_string_pretty(&config)?;
config_file.write_all(serialized_config.as_bytes())?;
writeln!(config_file, "{}{serialized_config}", shebang.unwrap_or_default())?;

Ok(config_file)
}
Expand Down
6 changes: 6 additions & 0 deletions quickget/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
pub mod data_structures;

#[cfg(feature = "quickget")]
mod config_search;
#[cfg(feature = "quickget")]
mod error;
#[cfg(feature = "quickget")]
mod instance;
#[cfg(feature = "quickget")]
pub use config_search::{ConfigSearch, QuickgetConfig};
#[cfg(feature = "quickget")]
pub use error::{ConfigSearchError, DLError};
#[cfg(feature = "quickget")]
pub use instance::{QGDockerSource, QGDownload, QuickgetInstance};

0 comments on commit 1205d22

Please sign in to comment.