Skip to content

Commit

Permalink
fix restore
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvlach committed Jan 9, 2024
1 parent 66c4ffa commit e8b9591
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions agdb_server/src/db_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ impl DbPool {
let current_path = db_file(owner, db, config);
let backup_temp = db_backup_dir(owner, config).join(db);

self.get_pool_mut()?.remove(&db_name);
let mut pool = self.get_pool_mut()?;
pool.remove(&db_name);
std::fs::rename(&current_path, &backup_temp)?;
std::fs::rename(&backup_path, &current_path)?;
std::fs::rename(backup_temp, backup_path)?;
Expand All @@ -834,7 +835,7 @@ impl DbPool {
database.db_type,
current_path.to_string_lossy()
))?;
self.get_pool_mut()?.insert(db_name, server_db);
pool.insert(db_name, server_db);
database.backup = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
self.save_db(database)?;

Expand Down
7 changes: 7 additions & 0 deletions agdb_server/tests/routes/admin_user_remove_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ async fn remove_with_other() -> anyhow::Result<()> {
.admin_db_user_add(owner, db, user, DbUserRole::Write)
.await?;
server.api.admin_user_remove(owner).await?;
assert!(!server
.api
.admin_user_list()
.await?
.1
.iter()
.any(|u| u.name == *owner));
assert!(!Path::new(&server.data_dir).join(owner).exists());
server.api.user_login(user, user).await?;
assert!(server.api.db_list().await?.1.is_empty());
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion agdb_server/tests/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod db_rename_test;
mod db_user_add_test;
mod db_user_list;
mod db_user_remove_test;
mod server_test;
mod misc_routes;
mod user_change_password_test;
mod user_login_test;
mod user_logout_test;
9 changes: 0 additions & 9 deletions agdb_server/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,6 @@ impl TestServer {
format!("db{}", COUNTER.fetch_add(1, Ordering::SeqCst))
}

// pub async fn restart(&mut self) -> anyhow::Result<()> {
// let _guard = MUTEX
// .get_or_init(|| tokio::sync::Mutex::new(()))
// .lock()
// .await;
// *SERVER.write().await = Some(TestServerImpl::new().await?);
// Ok(())
// }

pub fn url(&self, uri: &str) -> String {
format!("{}:{}/api/v1{uri}", Self::url_base(), self.port)
}
Expand Down

0 comments on commit e8b9591

Please sign in to comment.