diff --git a/rust/agama-lib/src/bootloader/model.rs b/rust/agama-lib/src/bootloader/model.rs index 5cf6879eb6..b4491a4a8c 100644 --- a/rust/agama-lib/src/bootloader/model.rs +++ b/rust/agama-lib/src/bootloader/model.rs @@ -31,3 +31,13 @@ pub struct BootloaderSettings { #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option, } + +impl BootloaderSettings { + pub fn to_option(self) -> Option { + if self.stop_on_boot_menu.is_none() && self.timeout.is_none() { + None + } else { + Some(self) + } + } +} diff --git a/rust/agama-lib/src/bootloader/store.rs b/rust/agama-lib/src/bootloader/store.rs index b41b6d701d..4c5bf702fc 100644 --- a/rust/agama-lib/src/bootloader/store.rs +++ b/rust/agama-lib/src/bootloader/store.rs @@ -38,8 +38,8 @@ impl BootloaderStore { }) } - pub async fn load(&self) -> Result { - self.bootloader_client.get_config().await + pub async fn load(&self) -> Result, ServiceError> { + Ok(self.bootloader_client.get_config().await?.to_option()) } pub async fn store(&self, settings: &BootloaderSettings) -> Result<(), ServiceError> { diff --git a/rust/agama-lib/src/files/store.rs b/rust/agama-lib/src/files/store.rs index 126faadce4..ce6299d1bc 100644 --- a/rust/agama-lib/src/files/store.rs +++ b/rust/agama-lib/src/files/store.rs @@ -38,8 +38,13 @@ impl FilesStore { } /// loads the list of user files from http API - pub async fn load(&self) -> Result, ServiceError> { - self.files_client.get_files().await + pub async fn load(&self) -> Result>, ServiceError> { + let res = self.files_client.get_files().await?; + if res.is_empty() { + Ok(None) + } else { + Ok(Some(res)) + } } /// stores the list of user files via http API diff --git a/rust/agama-lib/src/install_settings.rs b/rust/agama-lib/src/install_settings.rs index 8ac45f697c..6fc8291e8c 100644 --- a/rust/agama-lib/src/install_settings.rs +++ b/rust/agama-lib/src/install_settings.rs @@ -43,14 +43,17 @@ use std::path::Path; #[serde(rename_all = "camelCase")] pub struct InstallSettings { #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] pub bootloader: Option, #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] pub files: Option>, #[serde(default)] pub hostname: Option, #[serde(default, flatten)] pub user: Option, #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] pub software: Option, #[serde(default)] pub product: Option, @@ -65,6 +68,7 @@ pub struct InstallSettings { #[serde(default)] pub localization: Option, #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] pub scripts: Option, } diff --git a/rust/agama-lib/src/scripts/settings.rs b/rust/agama-lib/src/scripts/settings.rs index 11e407d320..a05c0c0f2c 100644 --- a/rust/agama-lib/src/scripts/settings.rs +++ b/rust/agama-lib/src/scripts/settings.rs @@ -38,3 +38,17 @@ pub struct ScriptsConfig { #[serde(skip_serializing_if = "Option::is_none")] pub init: Option>, } + +impl ScriptsConfig { + pub fn to_option(self) -> Option { + if self.pre.is_none() + && self.post_partitioning.is_none() + && self.post.is_none() + && self.init.is_none() + { + None + } else { + Some(self) + } + } +} diff --git a/rust/agama-lib/src/software/settings.rs b/rust/agama-lib/src/software/settings.rs index c73a0da667..a3d4802bc7 100644 --- a/rust/agama-lib/src/software/settings.rs +++ b/rust/agama-lib/src/software/settings.rs @@ -33,3 +33,13 @@ pub struct SoftwareSettings { #[serde(skip_serializing_if = "Option::is_none")] pub packages: Option>, } + +impl SoftwareSettings { + pub fn to_option(self) -> Option { + if self.patterns.is_none() && self.packages.is_none() { + None + } else { + Some(self) + } + } +} diff --git a/rust/agama-lib/src/store.rs b/rust/agama-lib/src/store.rs index 60020e43b0..643bbe6e8a 100644 --- a/rust/agama-lib/src/store.rs +++ b/rust/agama-lib/src/store.rs @@ -76,15 +76,15 @@ impl Store { /// Loads the installation settings from the HTTP interface. pub async fn load(&self) -> Result { let mut settings = InstallSettings { - bootloader: Some(self.bootloader.load().await?), - files: Some(self.files.load().await?), + bootloader: self.bootloader.load().await?, + files: self.files.load().await?, hostname: Some(self.hostname.load().await?), network: Some(self.network.load().await?), - software: Some(self.software.load().await?), + software: self.software.load().await?.to_option(), user: Some(self.users.load().await?), product: Some(self.product.load().await?), localization: Some(self.localization.load().await?), - scripts: Some(self.scripts.load().await?), + scripts: self.scripts.load().await?.to_option(), ..Default::default() }; diff --git a/rust/package/agama.changes b/rust/package/agama.changes index 72f0888aaf..952b748c19 100644 --- a/rust/package/agama.changes +++ b/rust/package/agama.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Apr 7 14:02:57 UTC 2025 - Josef Reidinger + +- Skip exporting scripts, files, bootloader and softare section + in profile if they are empty (gh#agama-project/agama#2250) + ------------------------------------------------------------------- Tue Apr 1 12:44:57 UTC 2025 - Ladislav Slezák