mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
fuckit: no patch db locks (#1969)
* fuck it: no patchdb locks * fix: Add the locking to the package during the backup. (#1979) * fix: Add the locking to the package during the backup. * fix: Lock for the uninstall of the package * switch patch-db to next Co-authored-by: J M <2364004+Blu-J@users.noreply.github.com>
This commit is contained in:
@@ -139,7 +139,7 @@ pub async fn action(
|
||||
.await
|
||||
.with_kind(crate::ErrorKind::NotFound)?
|
||||
.manifest()
|
||||
.get(&mut db, true)
|
||||
.get(&mut db)
|
||||
.await?
|
||||
.to_owned();
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ pub async fn backup_all(
|
||||
.await?;
|
||||
let all_packages = crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.get(&mut db, false)
|
||||
.get(&mut db)
|
||||
.await?
|
||||
.0
|
||||
.keys()
|
||||
@@ -297,7 +297,7 @@ async fn perform_backup<Db: DbHandle>(
|
||||
|
||||
for package_id in crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(&mut db, false)
|
||||
.keys(&mut db)
|
||||
.await?
|
||||
.into_iter()
|
||||
.filter(|id| package_ids.contains(id))
|
||||
@@ -317,7 +317,7 @@ async fn perform_backup<Db: DbHandle>(
|
||||
let main_status_model = installed_model.clone().status().main();
|
||||
|
||||
main_status_model.lock(&mut tx, LockType::Write).await?;
|
||||
let (started, health) = match main_status_model.get(&mut tx, true).await?.into_owned() {
|
||||
let (started, health) = match main_status_model.get(&mut tx).await?.into_owned() {
|
||||
MainStatus::Starting { .. } => (Some(Utc::now()), Default::default()),
|
||||
MainStatus::Running { started, health } => (Some(started), health.clone()),
|
||||
MainStatus::Stopped | MainStatus::Stopping | MainStatus::Restarting => {
|
||||
@@ -346,11 +346,7 @@ async fn perform_backup<Db: DbHandle>(
|
||||
.await?;
|
||||
tx.save().await?; // drop locks
|
||||
|
||||
let manifest = installed_model
|
||||
.clone()
|
||||
.manifest()
|
||||
.get(&mut db, false)
|
||||
.await?;
|
||||
let manifest = installed_model.clone().manifest().get(&mut db).await?;
|
||||
|
||||
ctx.managers
|
||||
.get(&(manifest.id.clone(), manifest.version.clone()))
|
||||
@@ -362,6 +358,11 @@ async fn perform_backup<Db: DbHandle>(
|
||||
.await;
|
||||
|
||||
let mut tx = db.begin().await?;
|
||||
let lock_package = crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.idx(&package_id)
|
||||
.lock(&mut tx, LockType::Write)
|
||||
.await;
|
||||
|
||||
installed_model.lock(&mut tx, LockType::Write).await?;
|
||||
|
||||
@@ -445,7 +446,7 @@ async fn perform_backup<Db: DbHandle>(
|
||||
root_ca_cert,
|
||||
ui: crate::db::DatabaseModel::new()
|
||||
.ui()
|
||||
.get(&mut db, true)
|
||||
.get(&mut db)
|
||||
.await?
|
||||
.into_owned(),
|
||||
})?,
|
||||
|
||||
@@ -137,7 +137,7 @@ impl BackupActions {
|
||||
.expect(db)
|
||||
.await?
|
||||
.marketplace_url()
|
||||
.get(db, true)
|
||||
.get(db)
|
||||
.await?
|
||||
.into_owned();
|
||||
let tmp_path = Path::new(BACKUP_DIR)
|
||||
@@ -237,7 +237,7 @@ impl BackupActions {
|
||||
.installed()
|
||||
.expect(db)
|
||||
.await?
|
||||
.get(db, true)
|
||||
.get(db)
|
||||
.await?;
|
||||
|
||||
let receipts = crate::config::ConfigReceipts::new(db).await?;
|
||||
|
||||
@@ -342,6 +342,11 @@ where
|
||||
for<'a> &'a mut Ex: Executor<'a, Database = Postgres>,
|
||||
{
|
||||
let mut tx = db.begin().await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.idx_model(&id)
|
||||
.lock(&mut tx, LockType::Write)
|
||||
.await?;
|
||||
let receipts = UninstallReceipts::new(&mut tx, id).await?;
|
||||
let entry = receipts.removing.get(&mut tx).await?;
|
||||
cleanup(ctx, &entry.manifest.id, &entry.manifest.version).await?;
|
||||
|
||||
@@ -63,7 +63,7 @@ pub async fn list(#[context] ctx: RpcContext) -> Result<Vec<(PackageId, Version)
|
||||
let mut hdl = ctx.db.handle();
|
||||
let package_data = crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.get(&mut hdl, true)
|
||||
.get(&mut hdl)
|
||||
.await?;
|
||||
|
||||
Ok(package_data
|
||||
@@ -601,6 +601,11 @@ pub async fn uninstall_dry(
|
||||
pub async fn uninstall_impl(ctx: RpcContext, id: PackageId) -> Result<(), Error> {
|
||||
let mut handle = ctx.db.handle();
|
||||
let mut tx = handle.begin().await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.idx_model(&id)
|
||||
.lock(&mut tx, LockType::Write)
|
||||
.await?;
|
||||
|
||||
let mut pde = crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
@@ -879,7 +884,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin + Send + Sync>(
|
||||
.package_data()
|
||||
.idx_model(dep)
|
||||
.map::<_, Manifest>(|pde| pde.manifest())
|
||||
.get(&mut ctx.db.handle(), false)
|
||||
.get(&mut ctx.db.handle())
|
||||
.await?
|
||||
.into_owned()
|
||||
{
|
||||
@@ -1119,7 +1124,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin + Send + Sync>(
|
||||
let mut deps = BTreeMap::new();
|
||||
for package in crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(&mut tx, true)
|
||||
.keys(&mut tx)
|
||||
.await?
|
||||
{
|
||||
// update dependency_info on dependents
|
||||
@@ -1153,7 +1158,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin + Send + Sync>(
|
||||
.await?
|
||||
.installed()
|
||||
.and_then(|i| i.current_dependencies().idx_model(pkg_id))
|
||||
.get(&mut tx, true)
|
||||
.get(&mut tx)
|
||||
.await?
|
||||
.to_owned()
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ impl ManagerMap {
|
||||
let mut res = BTreeMap::new();
|
||||
for package in crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(db, true)
|
||||
.keys(db)
|
||||
.await?
|
||||
{
|
||||
let man: Manifest = if let Some(manifest) = crate::db::DatabaseModel::new()
|
||||
@@ -61,7 +61,7 @@ impl ManagerMap {
|
||||
.idx_model(&package)
|
||||
.and_then(|pkg| pkg.installed())
|
||||
.map(|m| m.manifest())
|
||||
.get(db, true)
|
||||
.get(db)
|
||||
.await?
|
||||
.to_owned()
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ pub async fn fetch_properties(ctx: RpcContext, id: PackageId) -> Result<Value, E
|
||||
.idx_model(&id)
|
||||
.and_then(|p| p.installed())
|
||||
.map(|m| m.manifest())
|
||||
.get(&mut db, true)
|
||||
.get(&mut db)
|
||||
.await?
|
||||
.to_owned()
|
||||
.ok_or_else(|| Error::new(eyre!("{} is not installed", id), ErrorKind::NotFound))?;
|
||||
|
||||
@@ -440,7 +440,7 @@ async fn migrate(
|
||||
old_guid: &str,
|
||||
embassy_password: String,
|
||||
) -> Result<(Arc<String>, Hostname, OnionAddressV3, X509), Error> {
|
||||
use crate::util::Invoke;
|
||||
|
||||
*ctx.setup_status.write().await = Some(Ok(SetupStatus {
|
||||
bytes_transferred: 0,
|
||||
total_bytes: 110,
|
||||
|
||||
@@ -47,11 +47,7 @@ impl VersionT for Version {
|
||||
crate::hostname::ensure_hostname_is_set(db, &receipts).await?;
|
||||
receipts.id.set(db, generate_id()).await?;
|
||||
|
||||
let mut ui = crate::db::DatabaseModel::new()
|
||||
.ui()
|
||||
.get(db, false)
|
||||
.await?
|
||||
.clone();
|
||||
let mut ui = crate::db::DatabaseModel::new().ui().get(db).await?.clone();
|
||||
ui.merge_with(&DEFAULT_UI);
|
||||
crate::db::DatabaseModel::new().ui().put(db, &ui).await?;
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ impl VersionT for Version {
|
||||
|
||||
for package_id in crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(db, false)
|
||||
.keys(db)
|
||||
.await?
|
||||
.iter()
|
||||
{
|
||||
@@ -126,7 +126,7 @@ impl VersionT for Version {
|
||||
ui["auto-check-updates"] = Value::Bool(true);
|
||||
ui["pkg-order"] = json!(crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(db, false)
|
||||
.keys(db)
|
||||
.await?
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
|
||||
2
patch-db
2
patch-db
Submodule patch-db updated: c54a1f037c...953a224384
Reference in New Issue
Block a user