Commit df572398 authored by Roman Alifanov's avatar Roman Alifanov

Move Update from Manage to Query interface

parent 871ae5fa
......@@ -110,6 +110,9 @@ pub enum QueryCommands {
/// Check system integrity
Check,
/// Update package indexes
Update,
}
#[derive(Subcommand, Debug)]
......@@ -136,9 +139,6 @@ pub enum ManageCommands {
packages: Vec<String>,
},
/// Update package indexes
Update,
/// Upgrade system packages
Upgrade,
......
......@@ -20,6 +20,7 @@ trait EpmQuery {
async fn file_list(&self, package_name: String) -> zbus::fdo::Result<String>;
async fn check_install(&self, packages: Vec<String>) -> zbus::fdo::Result<String>;
async fn check_remove(&self, packages: Vec<String>, depends: bool) -> zbus::fdo::Result<String>;
async fn update(&self, transaction: String) -> zbus::fdo::Result<String>;
async fn check_upgrade(&self) -> zbus::fdo::Result<String>;
async fn check_auto_remove(&self) -> zbus::fdo::Result<String>;
async fn check_auto_orphans(&self) -> zbus::fdo::Result<String>;
......@@ -46,7 +47,6 @@ trait EpmManage {
async fn install(&self, packages: Vec<String>, transaction: String) -> zbus::fdo::Result<String>;
async fn remove(&self, packages: Vec<String>, purge: bool, depends: bool, transaction: String) -> zbus::fdo::Result<String>;
async fn download(&self, packages: Vec<String>) -> zbus::fdo::Result<String>;
async fn update(&self, transaction: String) -> zbus::fdo::Result<String>;
async fn upgrade(&self, transaction: String) -> zbus::fdo::Result<String>;
async fn clean(&self) -> zbus::fdo::Result<String>;
async fn auto_remove(&self, transaction: String) -> zbus::fdo::Result<String>;
......@@ -286,7 +286,7 @@ impl EpmClient {
}
pub async fn update(&self) -> Result<String> {
let proxy = EpmManageProxy::new(&self.connection).await?;
let proxy = EpmQueryProxy::new(&self.connection).await?;
let tx = uuid::Uuid::new_v4().to_string();
let tx_clone = tx.clone();
self.run_with_signals(tx, move || {
......
......@@ -109,35 +109,6 @@ impl ManageInterface {
to_json(&ApiResponse::success(result))
}
async fn update(
&self,
#[zbus(header)] header: zbus::message::Header<'_>,
transaction: String,
) -> zbus::fdo::Result<String> {
let sender = header
.sender()
.ok_or_else(|| zbus::fdo::Error::Failed("No sender".into()))?
.to_string();
check_authorization(&self.connection, &sender, ACTION_MANAGE)
.await
.map_err(|e| zbus::fdo::Error::Failed(e.to_string()))?;
let config = self.config.read().await;
let signal_emitter = SignalEmitter::new(self.connection.clone());
let tx = if transaction.is_empty() {
uuid::Uuid::new_v4().to_string()
} else {
transaction
};
let result = system::update_with_signals(&config, Some(signal_emitter), &tx)
.await
.map_err(|e| zbus::fdo::Error::Failed(e.to_string()))?;
to_json(&ApiResponse::success(result))
}
async fn upgrade(
&self,
#[zbus(header)] header: zbus::message::Header<'_>,
......
use std::sync::Arc;
use tokio::sync::RwLock;
use zbus::interface;
use zbus::{interface, Connection};
use crate::config::Config;
use crate::dbus::SignalEmitter;
use crate::eepm::commands::{info, install, play, remove, search, system};
use crate::types::ApiResponse;
......@@ -12,11 +13,12 @@ fn to_json<T: serde::Serialize>(data: &T) -> zbus::fdo::Result<String> {
pub struct QueryInterface {
config: Arc<RwLock<Config>>,
connection: Connection,
}
impl QueryInterface {
pub fn new(config: Arc<RwLock<Config>>) -> Self {
Self { config }
pub fn new(config: Arc<RwLock<Config>>, connection: Connection) -> Self {
Self { config, connection }
}
}
......@@ -102,6 +104,22 @@ impl QueryInterface {
to_json(&ApiResponse::success(result))
}
async fn update(&self, transaction: String) -> zbus::fdo::Result<String> {
let config = self.config.read().await;
let signal_emitter = SignalEmitter::new(self.connection.clone());
let tx = if transaction.is_empty() {
uuid::Uuid::new_v4().to_string()
} else {
transaction
};
let result = system::update_with_signals(&config, Some(signal_emitter), &tx)
.await
.map_err(|e| zbus::fdo::Error::Failed(e.to_string()))?;
to_json(&ApiResponse::success(result))
}
async fn check_upgrade(&self) -> zbus::fdo::Result<String> {
let config = self.config.read().await;
let result = system::check_upgrade(&config)
......
......@@ -20,7 +20,7 @@ impl EpmServer {
}
pub async fn register(&self, connection: &Connection) -> Result<()> {
let query = QueryInterface::new(self.config.clone());
let query = QueryInterface::new(self.config.clone(), connection.clone());
connection.object_server().at(DBUS_PATH, query).await?;
let manage = ManageInterface::new(self.config.clone(), connection.clone());
......
......@@ -99,12 +99,12 @@ async fn run_client_command(cmd: Commands, format: OutputFormat, show_progress:
QueryCommands::CheckAutoOrphans => client.check_autoorphans().await,
QueryCommands::CheckUpdateKernel => client.check_update_kernel().await,
QueryCommands::Check => client.check().await,
QueryCommands::Update => client.update().await,
},
Commands::Manage { cmd: m } => match m {
ManageCommands::Install { packages } => client.install(&packages).await,
ManageCommands::Remove { packages, purge, depends } => client.remove(&packages, purge, depends).await,
ManageCommands::Download { packages } => client.download(&packages).await,
ManageCommands::Update => client.update().await,
ManageCommands::Upgrade => client.upgrade().await,
ManageCommands::Clean => client.clean().await,
ManageCommands::AutoRemove => client.autoremove().await,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment