Skip to content

Commit

Permalink
manage the YoukiConfig file name itself because it's confusing.
Browse files Browse the repository at this point in the history
  • Loading branch information
utam0k committed Nov 14, 2021
1 parent f0596ea commit 75ab8d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
10 changes: 6 additions & 4 deletions crates/libcontainer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use oci_spec::runtime::{Hooks, Spec};

use crate::utils;

const YOUKI_CONFIG_NAME: &str = "yconfig.json";

/// A configuration for passing information obtained during container creation to other commands.
/// Keeping the information to a minimum improves performance.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
Expand All @@ -34,13 +36,13 @@ impl<'a> YoukiConfig {
}

pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()> {
let file = fs::File::create(path.as_ref())?;
let file = fs::File::create(path.as_ref().join(YOUKI_CONFIG_NAME))?;
serde_json::to_writer(&file, self)?;
Ok(())
}

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
let file = fs::File::open(path.as_ref())?;
let file = fs::File::open(path.as_ref().join(YOUKI_CONFIG_NAME))?;
Ok(serde_json::from_reader(&file)?)
}
}
Expand Down Expand Up @@ -69,8 +71,8 @@ mod tests {
let tmp = create_temp_dir("test_config_save_and_load").expect("create test directory");
let spec = Spec::default();
let config = YoukiConfig::from_spec(&spec, container_id)?;
config.save(tmp.join("yconfig.json"))?;
let act = YoukiConfig::load(tmp.join("yconfig.json"))?;
config.save(&tmp)?;
let act = YoukiConfig::load(&tmp)?;
assert_eq!(act, config);
Ok(())
}
Expand Down
7 changes: 3 additions & 4 deletions crates/libcontainer/src/container/container_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ impl Container {
log::debug!("container status: {:?}", self.status());
if self.can_delete() {
if self.root.exists() {
let config =
YoukiConfig::load(self.root.join("config.json")).with_context(|| {
format!("failed to load runtime spec for container {}", self.id())
})?;
let config = YoukiConfig::load(&self.root).with_context(|| {
format!("failed to load runtime spec for container {}", self.id())
})?;
log::debug!("config: {:?}", config);

// remove the directory storing container state
Expand Down
2 changes: 1 addition & 1 deletion crates/libcontainer/src/container/container_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Container {
bail!(err_msg);
}

let config = YoukiConfig::load(self.root.join("config.json"))
let config = YoukiConfig::load(&self.root)
.with_context(|| format!("failed to load runtime spec for container {}", self.id()))?;
if let Some(hooks) = config.hooks.as_ref() {
// While prestart is marked as deprecated in the OCI spec, the docker and integration test still
Expand Down
2 changes: 1 addition & 1 deletion crates/libcontainer/src/container/init_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> InitContainerBuilder<'a> {
.set_annotations(spec.annotations().clone());

let config = YoukiConfig::from_spec(&spec, container.id())?;
config.save(&container_dir.join("yconfig.json"))?;
config.save(&container_dir)?;

unistd::chdir(&container_dir)?;
let notify_path = container_dir.join(NOTIFY_FILE);
Expand Down

0 comments on commit 75ab8d3

Please sign in to comment.