diff --git a/Cargo.toml b/Cargo.toml index 8741a1e..e612500 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] resolver = "2" members = [ - ".", + "ciel/", "cli/", ] @@ -13,44 +13,6 @@ authors = ["liushuyu ", "xtex "] repository = "https://github.com/AOSC-Dev/ciel-rs" edition = "2021" -[package] -name = "ciel" -version.workspace = true -description.workspace = true -license.workspace = true -authors.workspace = true -repository.workspace = true -edition.workspace = true - -[dependencies] -zbus = { version = "^5", features = ["blocking"] } -nix = { version = "0.29", features = ["fs", "hostname", "mount", "signal", "user"] } -toml = "0.8" -bincode = "1.3" -serde = { version = "1.0", features = ["derive"] } -git2 = "0.19" -libmount = { git = "https://github.com/liushuyu/libmount", rev = "6fe8dba03a6404dfe1013995dd17af1c4e21c97b" } -adler32 = "1.2" -rayon = "1.10" -tempfile = "3.14" -libsystemd-sys = "0.9" -walkdir = "2" -xattr = "^1" -rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] } -time = { version = "0.3", default-features = false, features = ["serde-human-readable", "macros"] } -fs3 = "0.5" -ar = "0.9" -faster-hex = "0.10" -flate2 = "1.0" -inotify = "0.11" -zstd = "0.13.2" -thiserror = "2.0.8" -log = "0.4.22" -test-log = { version = "0.2.16", features = ["log"] } -sha2 = "0.10.8" -tar = "0.4.43" -xz2 = "0.1.7" - [profile.release] lto = true diff --git a/ciel/Cargo.toml b/ciel/Cargo.toml new file mode 100644 index 0000000..07236b6 --- /dev/null +++ b/ciel/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "ciel" +version.workspace = true +description.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +edition.workspace = true + +[dependencies] +zbus = { version = "^5", features = ["blocking"] } +nix = { version = "0.29", features = ["fs", "hostname", "mount", "signal", "user"] } +toml = "0.8" +bincode = "1.3" +serde = { version = "1.0", features = ["derive"] } +git2 = "0.19" +libmount = { git = "https://github.com/liushuyu/libmount", rev = "6fe8dba03a6404dfe1013995dd17af1c4e21c97b" } +adler32 = "1.2" +rayon = "1.10" +tempfile = "3.14" +libsystemd-sys = "0.9" +walkdir = "2" +xattr = "^1" +rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] } +time = { version = "0.3", default-features = false, features = ["serde-human-readable", "macros"] } +fs3 = "0.5" +ar = "0.9" +faster-hex = "0.10" +flate2 = "1.0" +inotify = "0.11" +zstd = "0.13.2" +thiserror = "2.0.8" +log = "0.4.22" +test-log = { version = "0.2.16", features = ["log"] } +sha2 = "0.10.8" +tar = "0.4.43" +xz2 = "0.1.7" diff --git a/src/build.rs b/ciel/src/build.rs similarity index 100% rename from src/build.rs rename to ciel/src/build.rs diff --git a/src/container.rs b/ciel/src/container.rs similarity index 98% rename from src/container.rs rename to ciel/src/container.rs index 7f20a52..d046704 100644 --- a/src/container.rs +++ b/ciel/src/container.rs @@ -567,7 +567,9 @@ impl OwnedContainer { /// Destroies the owned container. pub fn discard(self) -> Result<()> { let instance = self.0.instance().to_owned(); - self.0.lock.force_unlock(); + if let Some(lock) = &self.0.lock { + lock.force_unlock(); + } forget(self); instance.destroy() } @@ -632,7 +634,7 @@ mod test { #[test] fn test_container_migration() { - let testdir = TestDir::from("testdata/old-workspace"); + let testdir = TestDir::from("old-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -645,7 +647,7 @@ mod test { #[test] fn test_container_state() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -658,7 +660,7 @@ mod test { #[test] fn test_owned_container() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -676,7 +678,7 @@ mod test { #[test] fn test_owned_container_leak() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -692,7 +694,7 @@ mod test { #[test] fn test_container_config_apt_repos() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); let inst = ws.instance("test").unwrap(); diff --git a/src/dbus_machine1_machine.rs b/ciel/src/dbus_machine1_machine.rs similarity index 100% rename from src/dbus_machine1_machine.rs rename to ciel/src/dbus_machine1_machine.rs diff --git a/src/dbus_machine1_manager.rs b/ciel/src/dbus_machine1_manager.rs similarity index 100% rename from src/dbus_machine1_manager.rs rename to ciel/src/dbus_machine1_manager.rs diff --git a/src/fs/mod.rs b/ciel/src/fs/mod.rs similarity index 100% rename from src/fs/mod.rs rename to ciel/src/fs/mod.rs diff --git a/src/fs/overlayfs.rs b/ciel/src/fs/overlayfs.rs similarity index 100% rename from src/fs/overlayfs.rs rename to ciel/src/fs/overlayfs.rs diff --git a/src/fs/tmpfs.rs b/ciel/src/fs/tmpfs.rs similarity index 100% rename from src/fs/tmpfs.rs rename to ciel/src/fs/tmpfs.rs diff --git a/src/instance.rs b/ciel/src/instance.rs similarity index 97% rename from src/instance.rs rename to ciel/src/instance.rs index 83c7f82..9a18695 100644 --- a/src/instance.rs +++ b/ciel/src/instance.rs @@ -255,7 +255,7 @@ readonly-tree = false #[test] fn test_instance() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); @@ -276,7 +276,7 @@ readonly-tree = false #[test] fn test_instance_migration() { - let testdir = TestDir::from("testdata/old-workspace"); + let testdir = TestDir::from("old-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -286,7 +286,7 @@ readonly-tree = false #[test] fn test_instance_destroy() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); assert_eq!( diff --git a/src/lib.rs b/ciel/src/lib.rs similarity index 98% rename from src/lib.rs rename to ciel/src/lib.rs index 9170ae5..92dcf0b 100644 --- a/src/lib.rs +++ b/ciel/src/lib.rs @@ -119,9 +119,9 @@ pub(crate) mod test { use tempfile::TempDir; use crate::{ - Result, repo::SimpleAptRepository, workspace::{Workspace, WorkspaceConfig}, + Result, }; pub fn is_root() -> bool { @@ -144,6 +144,7 @@ pub(crate) mod test { } fn copy_file(from: &Path, to: &Path) { + assert!(from.exists()); if from.is_symlink() { std::os::unix::fs::symlink(fs::read_link(from).unwrap(), to).unwrap(); } else if from.is_file() { @@ -170,7 +171,7 @@ pub(crate) mod test { pub fn from(template: &str) -> Self { let dir = Self::new(); println!("copying test data: {} -> {:?}", template, dir.path()); - copy_file(Path::new(template), dir.path()); + copy_file(&Path::new("testdata").join(template), dir.path()); dir } diff --git a/src/machine.rs b/ciel/src/machine.rs similarity index 99% rename from src/machine.rs rename to ciel/src/machine.rs index 287934d..7784ed8 100644 --- a/src/machine.rs +++ b/ciel/src/machine.rs @@ -338,7 +338,7 @@ mod test { #[test(ignore)] fn test_container_boot() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); diff --git a/src/repo/mod.rs b/ciel/src/repo/mod.rs similarity index 98% rename from src/repo/mod.rs rename to ciel/src/repo/mod.rs index a066804..7062d04 100644 --- a/src/repo/mod.rs +++ b/ciel/src/repo/mod.rs @@ -110,7 +110,7 @@ mod test { #[test] fn test_simple_apt_repo_refresh() { - let testdir = TestDir::from("testdata/simple-repo"); + let testdir = TestDir::from("simple-repo"); let repo = testdir.apt_repo(); repo.refresh().unwrap(); assert_eq!( diff --git a/src/repo/monitor.rs b/ciel/src/repo/monitor.rs similarity index 100% rename from src/repo/monitor.rs rename to ciel/src/repo/monitor.rs diff --git a/src/repo/scan.rs b/ciel/src/repo/scan.rs similarity index 97% rename from src/repo/scan.rs rename to ciel/src/repo/scan.rs index 9a67e17..3df22e7 100644 --- a/src/repo/scan.rs +++ b/ciel/src/repo/scan.rs @@ -156,7 +156,7 @@ mod test { #[test] fn test_collect_all_packages() { - let testdir = TestDir::from("testdata/simple-repo"); + let testdir = TestDir::from("simple-repo"); assert_eq!( collect_all_packages(testdir.path().join("debs")).unwrap(), vec![ @@ -169,7 +169,7 @@ mod test { #[test] fn test_scan_single_deb_simple() { - let testdir = TestDir::from("testdata/simple-repo"); + let testdir = TestDir::from("simple-repo"); assert_eq!( String::from_utf8( scan_single_deb_simple( @@ -204,7 +204,7 @@ SHA256: dd386883fa246cc50826cced5df4353b64a490d3f0f487e2d8764b4d7d00151e #[test] fn test_scan_packages_simple() { - let testdir = TestDir::from("testdata/simple-repo"); + let testdir = TestDir::from("simple-repo"); assert_eq!( String::from_utf8( scan_packages_simple( diff --git a/src/workspace.rs b/ciel/src/workspace.rs similarity index 97% rename from src/workspace.rs rename to ciel/src/workspace.rs index c9c29b7..7e00458 100644 --- a/src/workspace.rs +++ b/ciel/src/workspace.rs @@ -640,7 +640,7 @@ volatile-mount = false #[test] fn test_workspace_migration_v3() { // migration from Ciel <= 3.6.0 - let testdir = TestDir::from("testdata/old-workspace"); + let testdir = TestDir::from("old-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -654,7 +654,7 @@ volatile-mount = false #[test] fn test_workspace_migration_v2() { // migration from Ciel 2.x.x - let testdir = TestDir::from("testdata/v2-workspace"); + let testdir = TestDir::from("v2-workspace"); let ws = testdir.workspace().unwrap(); dbg!(&ws); assert!(ws.is_system_loaded()); @@ -664,7 +664,7 @@ volatile-mount = false #[test] fn test_incompatible_workspace() { - let testdir = TestDir::from("testdata/incompat-ws-version"); + let testdir = TestDir::from("incompat-ws-version"); assert!(matches!( testdir.workspace(), Err(Error::UnsupportedWorkspaceVersion(0)) @@ -673,13 +673,13 @@ volatile-mount = false #[test] fn test_broken_workspace() { - let testdir = TestDir::from("testdata/broken-workspace"); + let testdir = TestDir::from("broken-workspace"); assert!(matches!(testdir.workspace(), Err(Error::BrokenWorkspace))); } #[test] fn test_workspace_instances() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); assert_eq!( @@ -698,7 +698,7 @@ volatile-mount = false #[test] fn test_workspace_add_instance() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); assert_eq!( @@ -733,7 +733,7 @@ volatile-mount = false #[test] fn test_workspace_commit() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); let instance = workspace.instance("test").unwrap(); @@ -758,7 +758,7 @@ volatile-mount = false #[test] fn test_workspace_commit_tmpfs() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); let instance = workspace.instance("tmpfs").unwrap(); @@ -783,7 +783,7 @@ volatile-mount = false #[test] fn test_workspace_destroy() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); workspace.destroy().unwrap(); @@ -793,7 +793,7 @@ volatile-mount = false #[test] fn test_workspace_ephemeral_container() { - let testdir = TestDir::from("testdata/simple-workspace"); + let testdir = TestDir::from("simple-workspace"); let workspace = testdir.workspace().unwrap(); dbg!(&workspace); let cont = workspace diff --git a/testdata/broken-workspace/.ciel/data/config.toml b/ciel/testdata/broken-workspace/.ciel/data/config.toml similarity index 100% rename from testdata/broken-workspace/.ciel/data/config.toml rename to ciel/testdata/broken-workspace/.ciel/data/config.toml diff --git a/testdata/broken-workspace/.ciel/version b/ciel/testdata/broken-workspace/.ciel/version similarity index 100% rename from testdata/broken-workspace/.ciel/version rename to ciel/testdata/broken-workspace/.ciel/version diff --git a/testdata/incompat-ws-version/.ciel/data/config.toml b/ciel/testdata/incompat-ws-version/.ciel/data/config.toml similarity index 100% rename from testdata/incompat-ws-version/.ciel/data/config.toml rename to ciel/testdata/incompat-ws-version/.ciel/data/config.toml diff --git a/testdata/incompat-ws-version/.ciel/version b/ciel/testdata/incompat-ws-version/.ciel/version similarity index 100% rename from testdata/incompat-ws-version/.ciel/version rename to ciel/testdata/incompat-ws-version/.ciel/version diff --git a/testdata/old-workspace/.ciel/container/dist/.gitkeep b/ciel/testdata/old-workspace/.ciel/container/dist/.gitkeep similarity index 100% rename from testdata/old-workspace/.ciel/container/dist/.gitkeep rename to ciel/testdata/old-workspace/.ciel/container/dist/.gitkeep diff --git a/testdata/old-workspace/.ciel/container/instances/test/layers/diff/.gitkeep b/ciel/testdata/old-workspace/.ciel/container/instances/test/layers/diff/.gitkeep similarity index 100% rename from testdata/old-workspace/.ciel/container/instances/test/layers/diff/.gitkeep rename to ciel/testdata/old-workspace/.ciel/container/instances/test/layers/diff/.gitkeep diff --git a/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/acbs/forest.conf b/ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/acbs/forest.conf similarity index 100% rename from testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/acbs/forest.conf rename to ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/acbs/forest.conf diff --git a/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/apt/sources.list b/ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/apt/sources.list similarity index 100% rename from testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/apt/sources.list rename to ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/apt/sources.list diff --git a/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/autobuild/ab4cfg.sh b/ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/autobuild/ab4cfg.sh similarity index 100% rename from testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/autobuild/ab4cfg.sh rename to ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/autobuild/ab4cfg.sh diff --git a/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/systemd/resolved.conf b/ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/systemd/resolved.conf similarity index 100% rename from testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/systemd/resolved.conf rename to ciel/testdata/old-workspace/.ciel/container/instances/test/layers/local/etc/systemd/resolved.conf diff --git a/testdata/old-workspace/.ciel/data/config.toml b/ciel/testdata/old-workspace/.ciel/data/config.toml similarity index 100% rename from testdata/old-workspace/.ciel/data/config.toml rename to ciel/testdata/old-workspace/.ciel/data/config.toml diff --git a/testdata/old-workspace/.ciel/version b/ciel/testdata/old-workspace/.ciel/version similarity index 100% rename from testdata/old-workspace/.ciel/version rename to ciel/testdata/old-workspace/.ciel/version diff --git a/testdata/simple-repo/debs/Packages b/ciel/testdata/simple-repo/debs/Packages similarity index 100% rename from testdata/simple-repo/debs/Packages rename to ciel/testdata/simple-repo/debs/Packages diff --git a/testdata/simple-repo/debs/Release b/ciel/testdata/simple-repo/debs/Release similarity index 100% rename from testdata/simple-repo/debs/Release rename to ciel/testdata/simple-repo/debs/Release diff --git a/testdata/simple-repo/debs/a/aosc-os-feature-data_20241017.1-0_noarch.deb b/ciel/testdata/simple-repo/debs/a/aosc-os-feature-data_20241017.1-0_noarch.deb similarity index 100% rename from testdata/simple-repo/debs/a/aosc-os-feature-data_20241017.1-0_noarch.deb rename to ciel/testdata/simple-repo/debs/a/aosc-os-feature-data_20241017.1-0_noarch.deb diff --git a/testdata/simple-workspace/.ciel/container/dist/etc/os-release b/ciel/testdata/simple-workspace/.ciel/container/dist/etc/os-release similarity index 100% rename from testdata/simple-workspace/.ciel/container/dist/etc/os-release rename to ciel/testdata/simple-workspace/.ciel/container/dist/etc/os-release diff --git a/testdata/simple-workspace/.ciel/container/instances/test/config.toml b/ciel/testdata/simple-workspace/.ciel/container/instances/test/config.toml similarity index 100% rename from testdata/simple-workspace/.ciel/container/instances/test/config.toml rename to ciel/testdata/simple-workspace/.ciel/container/instances/test/config.toml diff --git a/testdata/simple-workspace/.ciel/container/instances/test/layers/.gitkeep b/ciel/testdata/simple-workspace/.ciel/container/instances/test/layers/.gitkeep similarity index 100% rename from testdata/simple-workspace/.ciel/container/instances/test/layers/.gitkeep rename to ciel/testdata/simple-workspace/.ciel/container/instances/test/layers/.gitkeep diff --git a/testdata/simple-workspace/.ciel/container/instances/tmpfs/config.toml b/ciel/testdata/simple-workspace/.ciel/container/instances/tmpfs/config.toml similarity index 100% rename from testdata/simple-workspace/.ciel/container/instances/tmpfs/config.toml rename to ciel/testdata/simple-workspace/.ciel/container/instances/tmpfs/config.toml diff --git a/testdata/simple-workspace/.ciel/data/config.toml b/ciel/testdata/simple-workspace/.ciel/data/config.toml similarity index 100% rename from testdata/simple-workspace/.ciel/data/config.toml rename to ciel/testdata/simple-workspace/.ciel/data/config.toml diff --git a/testdata/simple-workspace/.ciel/version b/ciel/testdata/simple-workspace/.ciel/version similarity index 100% rename from testdata/simple-workspace/.ciel/version rename to ciel/testdata/simple-workspace/.ciel/version diff --git a/testdata/simple-workspace/TREE/.gitkeep b/ciel/testdata/simple-workspace/TREE/.gitkeep similarity index 100% rename from testdata/simple-workspace/TREE/.gitkeep rename to ciel/testdata/simple-workspace/TREE/.gitkeep diff --git a/testdata/v2-workspace/.ciel/container/dist/.gitkeep b/ciel/testdata/v2-workspace/.ciel/container/dist/.gitkeep similarity index 100% rename from testdata/v2-workspace/.ciel/container/dist/.gitkeep rename to ciel/testdata/v2-workspace/.ciel/container/dist/.gitkeep diff --git a/testdata/v2-workspace/.ciel/container/instances/test/layers/diff/.gitkeep b/ciel/testdata/v2-workspace/.ciel/container/instances/test/layers/diff/.gitkeep similarity index 100% rename from testdata/v2-workspace/.ciel/container/instances/test/layers/diff/.gitkeep rename to ciel/testdata/v2-workspace/.ciel/container/instances/test/layers/diff/.gitkeep diff --git a/testdata/v2-workspace/.ciel/container/instances/test/layers/local/.gitkeep b/ciel/testdata/v2-workspace/.ciel/container/instances/test/layers/local/.gitkeep similarity index 100% rename from testdata/v2-workspace/.ciel/container/instances/test/layers/local/.gitkeep rename to ciel/testdata/v2-workspace/.ciel/container/instances/test/layers/local/.gitkeep diff --git a/testdata/v2-workspace/.ciel/version b/ciel/testdata/v2-workspace/.ciel/version similarity index 100% rename from testdata/v2-workspace/.ciel/version rename to ciel/testdata/v2-workspace/.ciel/version diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ce0ce24..c3fe43d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -9,7 +9,7 @@ edition.workspace = true [dependencies] anyhow = "1.0.94" -ciel = { version = "4.0.0", path = ".." } +ciel = { version = "4.0.0", path = "../ciel" } clap = { version = "^4", features = ["string", "env"] } console = "0.15.10" dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }