Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ members = [
resolver = "2"

[workspace.package]
# required by zbus 5
rust-version = "1.81"
rust-version = "1.88"
edition = "2021"
6 changes: 3 additions & 3 deletions rust/agama-autoinstall/src/auto_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ impl ConfigAutoLoader {
/// locations. It does not report problems for these locations.
///
/// See [Self::load] for further information.
pub async fn load(&self, urls: &Vec<String>) -> anyhow::Result<()> {
pub async fn load(&self, urls: &[String]) -> anyhow::Result<()> {
let loader = ConfigLoader::new(self.insecure);
if urls.is_empty() {
self.load_predefined_config(loader).await
} else {
self.load_user_config(loader, &urls).await
self.load_user_config(loader, urls).await
}
}

Expand All @@ -90,7 +90,7 @@ impl ConfigAutoLoader {
/// Loads configuration files from pre-defined locations.
async fn load_predefined_config(&self, loader: ConfigLoader) -> anyhow::Result<()> {
for url in PREDEFINED_LOCATIONS {
match loader.load(&url).await {
match loader.load(url).await {
Ok(()) => {
println!("Configuration loaded from {url}");
return Ok(());
Expand Down
12 changes: 6 additions & 6 deletions rust/agama-autoinstall/src/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl ScriptsRunner {
pub async fn run(&mut self, url: &str) -> anyhow::Result<()> {
create_dir_all(&self.path)?;

let file_name = self.file_name_for(&url)?;
let file_name = self.file_name_for(url)?;

let path = self.path.join(&file_name);
self.save_script(url, &path).await?;
Expand All @@ -92,17 +92,17 @@ impl ScriptsRunner {
}

fn file_name_for(&mut self, url: &str) -> anyhow::Result<PathBuf> {
let parsed = Url::parse(&url)?;
let parsed = Url::parse(url)?;

self.idx += 1;
let unnamed = PathBuf::from(format!("{}-unnamed.sh", self.idx));

let Some(path) = parsed.path_segments() else {
let Some(mut path) = parsed.path_segments() else {
return Ok(unnamed);
};

Ok(path
.last()
.next_back()
.map(|p| PathBuf::from(format!("{}-{p}", self.idx)))
.unwrap_or(unnamed))
}
Expand All @@ -113,11 +113,11 @@ impl ScriptsRunner {
.write(true)
.truncate(true)
.mode(0o700)
.open(&path)?;
.open(path)?;

while let Err(error) = Transfer::get(url, &mut file, self.insecure) {
eprintln!("Could not load the script from {url}: {error}");
if !self.should_retry(&url, &error.to_string()).await? {
if !self.should_retry(url, &error.to_string()).await? {
return Err(anyhow!(error));
}
}
Expand Down
24 changes: 5 additions & 19 deletions rust/agama-bootloader/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

use agama_utils::{
actor::{self, Actor, Handler, MessageHandler},
api::{bootloader::Config, Issue},
issue,
api::bootloader::Config,
};
use async_trait::async_trait;

Expand All @@ -45,19 +44,16 @@ pub enum Error {
pub struct Starter {
connection: zbus::Connection,
client: Option<Box<dyn client::BootloaderClient + Send + 'static>>,
issues: Handler<issue::Service>,
}

impl Starter {
/// Creates a new starter.
///
/// * `connection`: connection to the D-Bus.
/// * `issues`: handler to the issues service.
pub fn new(connection: zbus::Connection, issues: Handler<issue::Service>) -> Self {
pub fn new(connection: zbus::Connection) -> Self {
Self {
connection,
client: None,
issues,
}
}

Expand All @@ -73,10 +69,7 @@ impl Starter {
Some(client) => client,
None => Box::new(Client::new(self.connection.clone()).await?),
};
let service = Service {
client: client,
issues: self.issues,
};
let service = Service { client };
let handler = actor::spawn(service);
Ok(handler)
}
Expand All @@ -87,18 +80,11 @@ impl Starter {
/// It is responsible for handling the bootloader configuration.
pub struct Service {
client: Box<dyn client::BootloaderClient + Send + 'static>,
issues: Handler<issue::Service>,
}

impl Service {
pub fn starter(connection: zbus::Connection, issues: Handler<issue::Service>) -> Starter {
Starter::new(connection, issues)
}

/// Returns configuration issues.
fn find_issues(&self) -> Vec<Issue> {
// TODO: get issues from bootloader proposal
vec![]
pub fn starter(connection: zbus::Connection) -> Starter {
Starter::new(connection)
}
}

Expand Down
10 changes: 8 additions & 2 deletions rust/agama-bootloader/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ pub struct TestClient {
state: Arc<Mutex<TestClientState>>,
}

impl Default for TestClient {
fn default() -> Self {
Self::new()
}
}

impl TestClient {
pub fn new() -> Self {
let state = TestClientState::default();
Expand Down Expand Up @@ -88,11 +94,11 @@ impl BootloaderClient for TestClient {

/// Starts a testing storage service.
pub async fn start_service(
issues: Handler<issue::Service>,
_issues: Handler<issue::Service>,
dbus: zbus::Connection,
) -> Handler<Service> {
let client = TestClient::new();
Starter::new(dbus, issues)
Starter::new(dbus)
.with_client(client)
.start()
.await
Expand Down
7 changes: 2 additions & 5 deletions rust/agama-cli/src/auth_tokens_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ impl AuthTokensFile {
/// Default path for the tokens file in user's home directory.
pub fn default_path() -> io::Result<PathBuf> {
let Some(path) = home::home_dir() else {
return Err(io::Error::new(
io::ErrorKind::Other,
"Cannot find the user's home directory",
));
return Err(io::Error::other("Cannot find the user's home directory"));
};

Ok(path.join(AUTH_TOKENS_FILE))
Expand Down Expand Up @@ -141,7 +138,7 @@ mod tests {
#[test]
fn test_remove_host() {
let path = Path::new("tests/tokens.json");
let mut file = AuthTokensFile::read_from_path(&path).unwrap();
let mut file = AuthTokensFile::read_from_path(path).unwrap();
assert!(file.get_token("my-server.lan").is_some());

file.remove_host("my-server.lan");
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ async fn edit(
// FIXME: invalid profile still gets loaded
let updated =
std::fs::read_to_string(&path).context(format!("Reading from file {:?}", path))?;
validate(&http_client, CliInput::Full(updated.clone()), false).await?;
validate(http_client, CliInput::Full(updated.clone()), false).await?;
return Ok(serde_json::from_str(&updated)?);
}

Expand Down Expand Up @@ -397,7 +397,7 @@ async fn monitor_progress(monitor: MonitorClient) -> anyhow::Result<()> {
let task = tokio::spawn(async move {
show_progress(monitor, true).await;
});
let _ = task.await?;
task.await?;

Ok(())
}
4 changes: 2 additions & 2 deletions rust/agama-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async fn build_http_client(
if let Some(token) = find_client_token(&client.base_url) {
return Ok(client.authenticated(&token)?);
}
return Err(ServiceError::NotAuthenticated.into());
Err(ServiceError::NotAuthenticated.into())
} else {
Ok(client.unauthenticated()?)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ async fn build_ws_client(api_url: Url, insecure: bool) -> anyhow::Result<WebSock
/// Build the API url from the host.
///
/// * `host`: ip or host name. The protocol is optional, using https if omitted (e.g, "myserver",
/// "http://myserver", "192.168.100.101").
/// "http://myserver", "192.168.100.101").
pub fn api_url(host: String) -> anyhow::Result<Url> {
let sanitized_host = host.trim_end_matches('/').to_string();

Expand Down
4 changes: 2 additions & 2 deletions rust/agama-cli/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ impl ProgressMonitor {
// and finish all that no longer have progress
let mut to_remove = vec![];
for (scope, bar) in &bars {
if !active_scopes.contains(&scope) {
if !active_scopes.contains(scope) {
bar.finish_with_message("done");
to_remove.push(scope.clone());
to_remove.push(*scope);
}
}
for scope in to_remove {
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-cli/src/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct AnswersWrapper {
}

async fn set_answers(client: HTTPClient, path: &str) -> anyhow::Result<()> {
let file = File::open(&path)?;
let file = File::open(path)?;
let reader = BufReader::new(file);
let wrapper: AnswersWrapper = serde_json::from_reader(reader)?;
client.set_answers(wrapper.answers).await?;
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mod tests {
.call(message::RunScripts::new(ScriptsGroup::Pre))
.await
.unwrap();
assert_eq!(ran, false);
assert!(!ran);

let test_file_1 = ctx.tmp_dir.path().join("file-1.txt");
let test_file_2 = ctx.tmp_dir.path().join("file-2.txt");
Expand All @@ -119,7 +119,7 @@ mod tests {
pre_script_json, init_script_json
);

let config: Config = serde_json::from_str(&config).unwrap();
let config: Config = serde_json::from_str(config.as_str()).unwrap();
ctx.handler
.call(message::SetConfig::with(config))
.await
Expand All @@ -130,7 +130,7 @@ mod tests {
.call(message::RunScripts::new(ScriptsGroup::Pre))
.await
.unwrap();
assert_eq!(ran, true);
assert!(ran);

// Wait until the scripts are executed.
while let Ok(event) = ctx.events_rx.recv().await {
Expand All @@ -150,7 +150,7 @@ mod tests {
let config =
r#"{ "files": [{ "destination": "/etc/README.md", "content": "Some text" }] }"#;

let config: Config = serde_json::from_str(&config).unwrap();
let config: Config = serde_json::from_str(config).unwrap();
ctx.handler
.call(message::SetConfig::with(config))
.await
Expand Down
10 changes: 5 additions & 5 deletions rust/agama-files/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ScriptsRunner {
///
/// * `scripts`: scripts to run.
pub async fn run(&self, scripts: &[&Script]) -> Result<(), Error> {
let scripts: Vec<_> = self.find_scripts_to_run(&scripts);
let scripts: Vec<_> = self.find_scripts_to_run(scripts);
self.start_progress(&scripts);

let mut resolv_linked = false;
Expand Down Expand Up @@ -130,7 +130,7 @@ impl ScriptsRunner {
return Ok(());
};

if !self.should_retry(&script, error).await? {
if !self.should_retry(script, error).await? {
return Ok(());
}
}
Expand All @@ -157,7 +157,7 @@ impl ScriptsRunner {
}

let answer = ask_question(&self.questions, question).await?;
return Ok(answer.action == "Yes");
Ok(answer.action == "Yes")
}

/// Runs the script at the given path.
Expand Down Expand Up @@ -218,7 +218,7 @@ impl ScriptsRunner {
/// It exclues any script that already ran.
fn find_scripts_to_run<'a>(&self, scripts: &[&'a Script]) -> Vec<&'a Script> {
scripts
.into_iter()
.iter()
.filter(|s| {
let stdout_file = self
.workdir
Expand Down Expand Up @@ -353,7 +353,7 @@ mod tests {
chroot: Some(chroot),
});
script
.write(&self.scripts_dir())
.write(self.scripts_dir())
.expect("Could not write the script");
script
}
Expand Down
3 changes: 1 addition & 2 deletions rust/agama-files/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ impl Service {
}
packages.push(Resolvable::new("agama-scripts", ResolvableType::Package));
}
_ = self
.software
self.software
.call(agama_software::message::SetResolvables::new(
"agama-scripts".to_string(),
packages,
Expand Down
7 changes: 1 addition & 6 deletions rust/agama-hostname/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ mod tests {
struct Context {
events_rx: broadcast::Receiver<Event>,
handler: Handler<Service>,
issues: Handler<issue::Service>,
}

impl AsyncTestContext for Context {
Expand All @@ -66,11 +65,7 @@ mod tests {

let handler = start_service(events_tx, issues.clone()).await;

Self {
events_rx,
handler,
issues,
}
Self { events_rx, handler }
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-hostname/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait ModelAdapter: Send + 'static {
let name = self.static_hostname()?;

Ok(SystemInfo {
r#static: (!name.is_empty()).then(|| name),
r#static: (!name.is_empty()).then_some(name),
hostname: self.hostname()?,
})
}
Expand Down
1 change: 0 additions & 1 deletion rust/agama-iscsi/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use agama_utils::{
progress,
};
use serde::Deserialize;
use serde_json;
use tokio::sync::broadcast;
use tokio_stream::StreamExt;
use zbus::{message, Connection, MatchRule, MessageStream};
Expand Down
6 changes: 6 additions & 0 deletions rust/agama-iscsi/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ pub struct TestClient {
state: Arc<Mutex<TestClientState>>,
}

impl Default for TestClient {
fn default() -> Self {
Self::new()
}
}

impl TestClient {
pub fn new() -> Self {
let state = TestClientState::default();
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-l10n/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {
locale: Some("xx_XX.UTF-8".to_string()),
timezone: Some("Unknown/Unknown".to_string()),
};
let _ = ctx.handler.call(message::SetConfig::with(config)).await?;
ctx.handler.call(message::SetConfig::with(config)).await?;

let found_issues = ctx.issues.call(issue::message::Get).await?;
let l10n_issues = found_issues.get(&Scope::L10n).unwrap();
Expand Down
Loading
Loading