Skip to content

Commit

Permalink
refactor: move core crate into subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
xtexChooser committed Jan 11, 2025
1 parent 694e33c commit cba1954
Show file tree
Hide file tree
Showing 43 changed files with 68 additions and 66 deletions.
40 changes: 1 addition & 39 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"
members = [
".",
"ciel/",
"cli/",
]

Expand All @@ -13,44 +13,6 @@ authors = ["liushuyu <[email protected]>", "xtex <[email protected]>"]
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

Expand Down
37 changes: 37 additions & 0 deletions ciel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
14 changes: 8 additions & 6 deletions src/container.rs → ciel/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/instance.rs → ciel/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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());
Expand All @@ -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!(
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs → ciel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/machine.rs → ciel/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/repo/mod.rs → ciel/src/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/repo/scan.rs → ciel/src/repo/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 10 additions & 10 deletions src/workspace.rs → ciel/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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))
Expand All @@ -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!(
Expand All @@ -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!(
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down

0 comments on commit cba1954

Please sign in to comment.