Skip to content

Commit

Permalink
Merge pull request #46 from OSInside/make-flake-ctl-read-config-file
Browse files Browse the repository at this point in the history
Make sure flake-ctl also reads /etc/flakes.yml
  • Loading branch information
schaefi authored Nov 4, 2024
2 parents 1b030b3 + 593e9f0 commit 0c7adea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion firecracker-pilot/guestvm-tools/sci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ fn move_mounts(new_root: &str) {
!*/
// /run
let mut call = Command::new("mount");
call.arg("--bind").arg("/run").arg(&format!("{}/run", new_root));
call.arg("--bind").arg("/run").arg(format!("{}/run", new_root));
debug(&format!("EXEC: mount -> {:?}", call.get_args()));
match call.status() {
Ok(_) => debug("Bind mounted /run"),
Expand Down
1 change: 1 addition & 0 deletions flake-ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ futures-util = { version = "0.3" }
indicatif = { version = "0.15" }
tokio = { version = "1.32", features = ["full"] }
tempfile = { version = "3.4" }
flakes = { version = "3.0.13", path = "../common" }
21 changes: 11 additions & 10 deletions flake-ctl/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use glob::glob;
use std::fs;
use std::os::unix::fs::symlink;
use std::path::Path;
use flakes::config::get_flakes_dir;

pub fn register(app: Option<&String>, target: Option<&String>, engine: &str) -> bool {
/*!
Expand Down Expand Up @@ -77,7 +78,7 @@ pub fn register(app: Option<&String>, target: Option<&String>, engine: &str) ->
.unwrap()
.to_str()
.unwrap();
let app_config_dir = format!("{}/{}.d", defaults::FLAKE_DIR, &app_basename);
let app_config_dir = format!("{}/{}.d", get_flakes_dir(), &app_basename);
match fs::create_dir_all(&app_config_dir) {
Ok(dir) => dir,
Err(error) => {
Expand Down Expand Up @@ -122,7 +123,7 @@ pub fn create_container_config(
.unwrap()
.to_str()
.unwrap();
let app_config_file = format!("{}/{}.yaml", defaults::FLAKE_DIR, &app_basename);
let app_config_file = format!("{}/{}.yaml", get_flakes_dir(), &app_basename);
match app_config::AppConfig::save_container(
Path::new(&app_config_file),
container,
Expand Down Expand Up @@ -176,7 +177,7 @@ pub fn create_vm_config(
.unwrap()
.to_str()
.unwrap();
let app_config_file = format!("{}/{}.yaml", defaults::FLAKE_DIR, &app_basename);
let app_config_file = format!("{}/{}.yaml", get_flakes_dir(), &app_basename);
match app_config::AppConfig::save_vm(
Path::new(&app_config_file),
vm,
Expand Down Expand Up @@ -246,8 +247,8 @@ pub fn remove(app: &str, engine: &str, silent: bool) -> bool {
}
// remove config file and config directory
let app_basename = basename(&app.to_string());
let config_file = format!("{}/{}.yaml", defaults::FLAKE_DIR, &app_basename);
let app_config_dir = format!("{}/{}.d", defaults::FLAKE_DIR, &app_basename);
let config_file = format!("{}/{}.yaml", get_flakes_dir(), &app_basename);
let app_config_dir = format!("{}/{}.d", get_flakes_dir(), &app_basename);
if Path::new(&config_file).exists() {
match fs::remove_file(&config_file) {
Ok(_) => {}
Expand Down Expand Up @@ -296,7 +297,7 @@ pub fn app_names() -> Vec<String> {
Read all flake config files
!*/
let mut flakes: Vec<String> = Vec::new();
let glob_pattern = format!("{}/*.yaml", defaults::FLAKE_DIR);
let glob_pattern = format!("{}/*.yaml", get_flakes_dir());
for config_file in glob(&glob_pattern).unwrap() {
match config_file {
Ok(filepath) => {
Expand Down Expand Up @@ -333,7 +334,7 @@ pub fn init(app: Option<&String>) -> bool {
/*!
Create required directory structure.
Symlink references to apps will be stored in defaults::FLAKE_DIR
Symlink references to apps will be stored in get_flakes_dir()
The init method makes sure to create this directory unless it
already exists.
!*/
Expand All @@ -343,16 +344,16 @@ pub fn init(app: Option<&String>) -> bool {
return false;
}
let mut flake_dir = String::new();
match fs::read_link(defaults::FLAKE_DIR) {
match fs::read_link(get_flakes_dir()) {
Ok(target) => {
flake_dir.push_str(&target.into_os_string().into_string().unwrap());
}
Err(_) => {
flake_dir.push_str(defaults::FLAKE_DIR);
flake_dir.push_str(&get_flakes_dir());
}
}
fs::create_dir_all(flake_dir).unwrap_or_else(|why| {
error!("Failed creating {}: {:?}", defaults::FLAKE_DIR, why.kind());
error!("Failed creating {}: {:?}", get_flakes_dir(), why.kind());
status = false
});
status
Expand Down

0 comments on commit 0c7adea

Please sign in to comment.