Skip to content

Commit

Permalink
add marketplace_url to backup metadata for service (#1688)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez authored Jul 25, 2022
1 parent 61da050 commit bdb906b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/src/backup/backup_bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ async fn perform_backup<Db: DbHandle>(
.backup
.create(
ctx,
&mut tx,
&package_id,
&manifest.title,
&manifest.version,
Expand Down
28 changes: 24 additions & 4 deletions backend/src/backup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use chrono::{DateTime, Utc};
use color_eyre::eyre::eyre;
use helpers::AtomicFile;
use patch_db::{DbHandle, HasModel, LockType};
use reqwest::Url;
use rpc_toolkit::command;
use serde::{Deserialize, Serialize};
use sqlx::{Executor, Sqlite};
Expand Down Expand Up @@ -61,6 +62,7 @@ pub fn package_backup() -> Result<(), Error> {
struct BackupMetadata {
pub timestamp: DateTime<Utc>,
pub tor_keys: BTreeMap<InterfaceId, String>,
pub marketplace_url: Option<Url>,
}

#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
Expand All @@ -84,10 +86,11 @@ impl BackupActions {
Ok(())
}

#[instrument(skip(ctx))]
pub async fn create(
#[instrument(skip(ctx, db))]
pub async fn create<Db: DbHandle>(
&self,
ctx: &RpcContext,
db: &mut Db,
pkg_id: &PackageId,
pkg_title: &str,
pkg_version: &Version,
Expand Down Expand Up @@ -125,6 +128,18 @@ impl BackupActions {
)
})
.collect();
let marketplace_url = crate::db::DatabaseModel::new()
.package_data()
.idx_model(pkg_id)
.expect(db)
.await?
.installed()
.expect(db)
.await?
.marketplace_url()
.get(db, true)
.await?
.into_owned();
let tmp_path = Path::new(BACKUP_DIR)
.join(pkg_id)
.join(format!("{}.s9pk", pkg_id));
Expand Down Expand Up @@ -156,6 +171,7 @@ impl BackupActions {
.write_all(&IoFormat::Cbor.to_vec(&BackupMetadata {
timestamp,
tor_keys,
marketplace_url,
})?)
.await?;
outfile.save().await.with_kind(ErrorKind::Filesystem)?;
Expand Down Expand Up @@ -227,17 +243,21 @@ impl BackupActions {
.package_data()
.lock(db, LockType::Write)
.await?;
crate::db::DatabaseModel::new()
let pde = crate::db::DatabaseModel::new()
.package_data()
.idx_model(pkg_id)
.expect(db)
.await?
.installed()
.expect(db)
.await?
.await?;
pde.clone()
.interface_addresses()
.put(db, &interfaces.install(&mut *secrets, pkg_id).await?)
.await?;
pde.marketplace_url()
.put(db, &metadata.marketplace_url)
.await?;

let entry = crate::db::DatabaseModel::new()
.package_data()
Expand Down

0 comments on commit bdb906b

Please sign in to comment.