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