mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
sdk improvements (#2877)
This commit is contained in:
@@ -574,7 +574,7 @@ impl Service {
|
||||
.send(
|
||||
Guid::new(),
|
||||
transition::backup::Backup {
|
||||
path: guard.path().join("data"),
|
||||
path: guard.path().to_path_buf(),
|
||||
},
|
||||
)
|
||||
.await??
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user