Skip to content

Commit

Permalink
Print installation clean up status
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Sep 30, 2023
1 parent ff31243 commit 92aaadf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
30 changes: 21 additions & 9 deletions ares-install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ares_connection_lib::session::DeviceSession;
use ares_connection_lib::transfer::{FileTransfer, TransferError};

pub(crate) trait InstallApp {
fn install_app<P: AsRef<Path>>(&self, package: P) -> Result<String, InstallError>;
fn install_app<P: AsRef<Path>>(&self, package: P) -> Result<(), InstallError>;
}

#[derive(Debug)]
Expand Down Expand Up @@ -48,7 +48,7 @@ struct InstallResponseDetails {
}

impl InstallApp for DeviceSession {
fn install_app<P: AsRef<Path>>(&self, package: P) -> Result<String, InstallError> {
fn install_app<P: AsRef<Path>>(&self, package: P) -> Result<(), InstallError> {
let mut file = File::open(&package)?;
let file_size = file.metadata()?.len();
let checksum = sha256::try_digest(package.as_ref()).map_err(|e| {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl InstallApp for DeviceSession {
});
pb.enable_steady_tick(Duration::from_millis(50));
pb.set_prefix("Uploading");
pb.set_style(ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {percent}% [{wide_bar}] {bytes}/{total_bytes} {eta} ETA")
pb.set_style(ProgressStyle::with_template("{prefix:10.bold.dim} {spinner} {percent:>3}% [{wide_bar}] {bytes}/{total_bytes} {eta} ETA")
.unwrap());

self.put(&mut file, &ipk_path, |transferred| {
Expand All @@ -96,7 +96,7 @@ impl InstallApp for DeviceSession {
pb.set_prefix("Installing");

let spinner_style =
ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}").unwrap();
ProgressStyle::with_template("{prefix:10.bold.dim} {spinner} {wide_msg}").unwrap();
pb.set_style(spinner_style);

let result = match self.subscribe(
Expand All @@ -123,16 +123,28 @@ impl InstallApp for DeviceSession {
},
)
})
.next(),
Err(e) => Some(Err(e.into())),
.next()
.unwrap_or_else(|| Ok(String::new())),
Err(e) => Err(e.into()),
};
pb.finish_and_clear();

if let Ok(package_id) = &result {
pb.suspend(|| println!("Installed package {}!", package_id));
}
pb.suspend(|| println!("Deleting uploaded package..."));

pb.set_prefix("Cleanup");
pb.set_message("Deleting uploaded package");

if let Err(e) = self.rm(&ipk_path) {
eprintln!("Failed to delete {}: {:?}", ipk_path, e);
pb.suspend(|| {
eprintln!("Failed to delete {}: {:?}", ipk_path, e);
});
}
pb.finish_and_clear();

return result.unwrap();
result?;
return Ok(());
}
}

Expand Down
2 changes: 1 addition & 1 deletion ares-install/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() {
}
} else if let Some(package) = cli.package {
match session.install_app(package) {
Ok(package_id) => println!("{package_id} installed."),
Ok(_) => {}
Err(e) => {
eprintln!("Failed to install: {e:?}");
exit(1);
Expand Down
17 changes: 14 additions & 3 deletions common/connection/src/luna/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ impl Iterator for Subscription {

impl Drop for Subscription {
fn drop(&mut self) {
self.ch.send_eof().unwrap_or(());
self.ch.request_send_signal("TERM").unwrap_or(());
self.ch.close().unwrap_or(());
self.close().unwrap_or_else(|e| {
eprintln!("Failed to close subscription: {e:?}");
return 0;
});
}
}

impl Subscription {
fn close(&mut self) -> Result<i32, Error> {
self.ch.send_eof()?;
self.ch.request_send_signal("TERM")?;
let status = self.ch.get_exit_status();
self.ch.close()?;
return Ok(status.unwrap_or(-1) as i32);
}
}

0 comments on commit 92aaadf

Please sign in to comment.