-
Notifications
You must be signed in to change notification settings - Fork 11
feat: uninstall #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/install_rework
Are you sure you want to change the base?
feat: uninstall #95
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,14 +21,13 @@ impl CommandInstall for TockloaderConnection { | |
| // obtain the binaries in a vector | ||
| let mut app_binaries: Vec<Vec<u8>> = Vec::new(); | ||
|
|
||
| let mut address = settings.start_address; | ||
| for app in app_attributes_list.iter() { | ||
| let address = app.address; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reasoning behind this change?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is simpler and safer this way, the apps can be spaced out in memory and incrementing the address might not work every time. We already have every app's address and size. |
||
| app_binaries.push( | ||
| self.read(address, app.tbf_header.total_size() as usize) | ||
| .await | ||
| .unwrap(), | ||
| ); | ||
| address += app.tbf_header.total_size() as u64; | ||
| } | ||
|
|
||
| let app = TockApp::from_tab(&tab, &settings).unwrap(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ pub mod list; | |
| pub mod probers; | ||
| pub mod reshuffle_apps; | ||
| pub mod serial; | ||
| pub mod uninstall; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| use async_trait::async_trait; | ||
|
|
||
| use crate::{ | ||
| attributes::app_attributes::AppAttributes, | ||
| command_impl::reshuffle_apps::{create_pkt, reshuffle_apps, TockApp}, | ||
| connection::{Connection, TockloaderConnection}, | ||
| errors::{InternalError, TockloaderError}, | ||
| CommandEraseApps, CommandList, CommandUninstall, IO, | ||
| }; | ||
|
|
||
| #[async_trait] | ||
| impl CommandUninstall for TockloaderConnection { | ||
| async fn uninstall_app( | ||
| &mut self, | ||
| app_name: Option<String>, | ||
| app_index: Option<usize>, | ||
| ) -> Result<(), TockloaderError> { | ||
| let settings = self.get_settings(); | ||
|
|
||
| let mut app_attributes_list: Vec<AppAttributes> = self.list().await?; | ||
|
|
||
| // Remove all apps with given name | ||
| if let Some(name) = app_name { | ||
| let _ = app_attributes_list | ||
| .retain(|app| app.tbf_header.get_package_name().unwrap_or("") != name); | ||
| } else if let Some(index) = app_index { | ||
| // Delete all apps, call erase | ||
| if index == 0 { | ||
| self.erase_apps().await?; | ||
| return Ok(()); | ||
| } | ||
| // Remove the selected index | ||
| app_attributes_list.remove(index - 1); | ||
| } else { | ||
| panic!("Called uninstall with wrong parameters!"); | ||
| } | ||
|
|
||
| let tock_app_list = app_attributes_list | ||
| .iter() | ||
| .map(TockApp::from_app_attributes) | ||
| .collect::<Vec<TockApp>>(); | ||
|
|
||
| // obtain the binaries in a vector | ||
| let mut app_binaries: Vec<Vec<u8>> = Vec::new(); | ||
|
|
||
| for app in app_attributes_list.iter() { | ||
| let address = app.address; | ||
| app_binaries.push( | ||
| self.read(address, app.tbf_header.total_size() as usize) | ||
| .await | ||
| .unwrap(), | ||
| ); | ||
| } | ||
|
|
||
| let configuration = | ||
| reshuffle_apps(&settings, tock_app_list).ok_or(TockloaderError::Internal( | ||
| InternalError::MisconfiguredBoardSettings("Can't fit new app".to_string()), | ||
| ))?; | ||
|
|
||
| // create the pkt, this contains all the binaries in a vec | ||
| let mut pkt = create_pkt(configuration, app_binaries, None, &settings); | ||
|
|
||
| pkt.append(&mut [0u8; 512].to_vec()); | ||
|
|
||
| log::debug!("pkt len {}", pkt.len()); | ||
| // write the pkt | ||
| let _ = self.write(settings.start_address, &pkt).await?; | ||
| Ok(()) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,20 @@ pub trait CommandInstall { | |
| async fn install_app(&mut self, tab_file: Tab) -> Result<(), TockloaderError>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| pub trait CommandUninstall { | ||
| /// This function is used for uninstalling apps | ||
| /// - app_name is Some(value) if --name is used, otherwise it is None | ||
| /// - app_index is Some(value) if the app is chosen from the list, None otherwise | ||
| /// | ||
| /// There is no scenario in which both are Some(value) or None | ||
| async fn uninstall_app( | ||
| &mut self, | ||
| app_name: Option<String>, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does uninstalling an with None name mean?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When calling the uninstall option we can specify the name of the app (or not), that's why the name is optional. If name is specified, index is None. |
||
| app_index: Option<usize>, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this index for?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter is the selected index from the provided apps list. When --name is not used, app_name is None and index is Some(value). There is no scenario in which both have Some() or None values. |
||
| ) -> Result<(), TockloaderError>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| pub trait CommandEraseApps { | ||
| async fn erase_apps(&mut self) -> Result<(), TockloaderError>; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this structure only used in CLI? What is its purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is used for displaying the list of installed apps.