Skip to content

Commit f012e56

Browse files
committed
wip wip wip wip - multi shell attachment persisting
1 parent 9dabf66 commit f012e56

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

debian/changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
debmagic (0.0.1-alpha1) UNRELEASED; urgency=medium
1+
debmagic (0.0.1-alpha1) forky; urgency=medium
22

33
* WIP: Initial release.
44

packages/debmagic/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "debmagic"
33
version = "0.0.1-alpha1"
44
edition = "2024"
5+
rust-version = "1.89"
56
documentation = "https://debmagic.readthedocs.org"
67
homepage = "https://github.com/SFTtech/debmagic"
78
repository = "https://github.com/SFTtech/debmagic.git"

packages/debmagic/src/build.rs

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
fs,
3+
io::{BufReader, BufWriter},
34
path::{Path, PathBuf},
45
};
56

@@ -44,38 +45,59 @@ fn create_driver_from_build_root(
4445
return Err(anyhow!("No build.json found"));
4546
}
4647

47-
let content = fs::read_to_string(&build_metadata_path)?;
48-
let metadata: BuildMetadata = serde_json::from_str(&content).with_context(|| {
49-
format!(
50-
"Failed to read build metadata from {} - invalid json",
51-
build_metadata_path.display()
52-
)
53-
})?;
54-
55-
match metadata.driver {
56-
BuildDriverType::Docker => Ok(Box::new(DriverDocker::from_build_metadata(
57-
&metadata.config,
58-
&config.docker,
59-
&metadata,
60-
))),
61-
BuildDriverType::Bare => Ok(Box::new(DriverBare::from_build_metadata(
62-
&metadata.config,
63-
&config.bare,
64-
&metadata,
65-
))),
66-
// BuildDriverType::Lxd => ...
67-
}
48+
let file = fs::OpenOptions::new()
49+
.read(true)
50+
.write(true)
51+
.open(&build_metadata_path)?;
52+
file.lock()?;
53+
54+
let result = || -> anyhow::Result<Box<dyn BuildDriver>> {
55+
let reader = BufReader::new(&file);
56+
let metadata: BuildMetadata = serde_json::from_reader(reader).with_context(|| {
57+
format!(
58+
"Failed to read build metadata from {} - invalid json",
59+
build_metadata_path.display()
60+
)
61+
})?;
62+
63+
let driver: anyhow::Result<Box<dyn BuildDriver>> = match &metadata.driver {
64+
BuildDriverType::Docker => Ok(Box::new(DriverDocker::from_build_metadata(
65+
&metadata.config,
66+
&config.docker,
67+
&metadata,
68+
))),
69+
BuildDriverType::Bare => Ok(Box::new(DriverBare::from_build_metadata(
70+
&metadata.config,
71+
&config.bare,
72+
&metadata,
73+
))),
74+
// BuildDriverType::Lxd => ...
75+
};
76+
if driver.is_ok() {
77+
let updated_metadata = BuildMetadata {
78+
num_shells_attached: metadata.num_shells_attached + 1,
79+
..metadata
80+
};
81+
let writer = BufWriter::new(&file);
82+
serde_json::to_writer_pretty(writer, &updated_metadata)
83+
.context("Failed to serialize build metadata")?;
84+
}
85+
driver
86+
}();
87+
file.unlock()?;
88+
result
6889
}
6990

7091
fn write_build_metadata(config: &BuildConfig, driver: &dyn BuildDriver) -> anyhow::Result<()> {
7192
let metadata = BuildMetadata {
7293
driver: driver.driver_type(),
7394
config: config.clone(),
7495
driver_metadata: driver.get_build_metadata(),
96+
num_shells_attached: 0,
7597
};
7698
let path = config.build_root_dir.join("build.json");
7799
let json =
78-
serde_json::to_string_pretty(&metadata).context("Failed serialize build metadata")?;
100+
serde_json::to_string_pretty(&metadata).context("Failed to serialize build metadata")?;
79101
fs::write(path, json)?;
80102
Ok(())
81103
}
@@ -138,7 +160,7 @@ fn prepare_build_env(
138160
output_dir: output_dir.to_path_buf(),
139161
build_root_dir: build_root,
140162
distro: "debian".to_string(),
141-
distro_version: "trixie".to_string(),
163+
distro_version: "forky".to_string(),
142164
dry_run: config.dry_run,
143165
sign_package: false,
144166
};

packages/debmagic/src/build/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct BuildMetadata {
2929
pub driver: BuildDriverType,
3030
pub config: BuildConfig,
3131
pub driver_metadata: DriverSpecificBuildMetadata,
32+
pub num_shells_attached: i64,
3233
}
3334

3435
#[derive(Debug, Clone, Serialize, Deserialize)]

0 commit comments

Comments
 (0)