sdk improvements (#2877)

This commit is contained in:
Aiden McClelland
2025-04-16 12:53:10 -06:00
committed by GitHub
parent 89f3fdc05f
commit 47b6509f70
11 changed files with 207 additions and 144 deletions

View File

@@ -574,7 +574,7 @@ impl Service {
.send(
Guid::new(),
transition::backup::Backup {
path: guard.path().join("data"),
path: guard.path().to_path_buf(),
},
)
.await??

View File

@@ -1,5 +1,6 @@
use std::path::PathBuf;
use futures::channel::oneshot;
use futures::FutureExt;
use models::ProcedureName;
@@ -28,10 +29,11 @@ impl Handler<Restore> for ServiceActor {
jobs: &BackgroundJobQueue,
) -> Self::Response {
// So Need a handle to just a single field in the state
let path = restore.path.clone();
let path = restore.path;
let seed = self.0.clone();
let state = self.0.persistent_container.state.clone();
let (send_res, recv_res) = oneshot::channel();
let transition = RemoteCancellable::new(
async move {
let backup_guard = seed
@@ -48,17 +50,10 @@ impl Handler<Restore> for ServiceActor {
});
Ok::<_, Error>(())
}
.map(|x| {
if let Err(err) = x {
tracing::debug!("{:?}", err);
tracing::warn!("{}", err);
}
}),
.map(|res| send_res.send(res)),
);
let cancel_handle = transition.cancellation_handle();
let transition = transition.shared();
let job_transition = transition.clone();
jobs.add_job(job_transition.map(|_| ()));
jobs.add_job(transition.map(|_| ()));
let mut old = None;
self.0.persistent_container.state.send_modify(|s| {
@@ -73,9 +68,9 @@ impl Handler<Restore> for ServiceActor {
if let Some(t) = old {
t.abort().await;
}
match transition.await {
None => Err(Error::new(eyre!("Restoring canceled"), ErrorKind::Unknown)),
Some(x) => Ok(x),
match recv_res.await {
Err(_) => Err(Error::new(eyre!("Restoring canceled"), ErrorKind::Unknown)),
Ok(res) => res,
}
}
}

View File

@@ -915,6 +915,16 @@ impl Drop for TmpDir {
}
}
pub async fn maybe_open_file(path: impl AsRef<Path>) -> Result<Option<File>, Error> {
let path = path.as_ref();
match File::open(path).await {
Ok(a) => Ok(Some(a)),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(e) => Err(e),
}
.with_ctx(|_| (ErrorKind::Filesystem, lazy_format!("open {path:?}")))
}
pub async fn open_file(path: impl AsRef<Path>) -> Result<File, Error> {
let path = path.as_ref();
File::open(path)