adds package list functionality

This commit is contained in:
Keagan McClelland
2021-10-23 19:15:47 -06:00
committed by Aiden McClelland
parent 678fa0731e
commit 78dcce7be5
2 changed files with 35 additions and 13 deletions

View File

@@ -6,6 +6,20 @@ use std::process::Stdio;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use color_eyre::eyre::{self, eyre};
use emver::VersionRange;
use futures::future::BoxFuture;
use futures::{FutureExt, StreamExt, TryStreamExt};
use http::StatusCode;
use patch_db::{DbHandle, LockType};
use reqwest::Response;
use rpc_toolkit::command;
use tokio::fs::{DirEntry, File, OpenOptions};
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt};
use tokio::process::Command;
use tokio_stream::wrappers::ReadDirStream;
use tracing::instrument;
use self::cleanup::cleanup_failed;
use crate::context::RpcContext;
use crate::db::model::{
@@ -26,19 +40,6 @@ use crate::util::io::copy_and_shutdown;
use crate::util::{display_none, display_serializable, AsyncFileExt, Version};
use crate::volume::asset_dir;
use crate::{Error, ResultExt};
use color_eyre::eyre::{self, eyre};
use emver::VersionRange;
use futures::future::BoxFuture;
use futures::{FutureExt, StreamExt, TryStreamExt};
use http::StatusCode;
use patch_db::{DbHandle, LockType};
use reqwest::Response;
use rpc_toolkit::command;
use tokio::fs::{DirEntry, File, OpenOptions};
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt};
use tokio::process::Command;
use tokio_stream::wrappers::ReadDirStream;
use tracing::instrument;
pub mod cleanup;
pub mod progress;
@@ -48,6 +49,26 @@ pub const PKG_PUBLIC_DIR: &'static str = "package-data/public";
pub const PKG_DOCKER_DIR: &'static str = "package-data/docker";
pub const PKG_WASM_DIR: &'static str = "package-data/wasm";
#[command(display(display_serializable))]
pub async fn list(#[context] ctx: RpcContext) -> Result<Vec<(PackageId, Version)>, Error> {
let mut hdl = ctx.db.handle();
let package_data = crate::db::DatabaseModel::new()
.package_data()
.get(&mut hdl, true)
.await?;
Ok(package_data
.0
.iter()
.filter_map(|(id, pde)| match pde {
PackageDataEntry::Installed { installed, .. } => {
Some((id.clone(), installed.manifest.version.clone()))
}
_ => None,
})
.collect())
}
#[command(display(display_none))]
#[instrument(skip(ctx))]
pub async fn install(

View File

@@ -87,6 +87,7 @@ pub fn server() -> Result<(), RpcError> {
action::action,
install::install,
install::uninstall,
install::list,
config::config,
control::start,
control::stop,