-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(libscoop|sync): basic support of uninstalling packages
What the `basic support` means is with this commit only packages without using PowerShell scripts (`pre_uninstall`, `uninstaller` and `post_uninstall`) are supported. Signed-off-by: Chawye Hsu <[email protected]>
- Loading branch information
Showing
14 changed files
with
632 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::{error::Fallible, internal, package::Package, Event, Session}; | ||
|
||
/// Unset all environment variables defined by a given package. | ||
pub fn remove(session: &Session, package: &Package) -> Fallible<()> { | ||
assert!(package.is_installed()); | ||
|
||
// Unset environment variables | ||
if let Some(env_set) = package.manifest().env_set() { | ||
if let Some(tx) = session.emitter() { | ||
let _ = tx.send(Event::PackageEnvVarRemoveStart); | ||
} | ||
|
||
let keys = env_set.keys(); | ||
for key in keys { | ||
internal::env::set(key, "")?; | ||
} | ||
|
||
if let Some(tx) = session.emitter() { | ||
let _ = tx.send(Event::PackageEnvVarRemoveDone); | ||
} | ||
} | ||
|
||
// Remove environment path | ||
if let Some(env_add_path) = package.manifest().env_add_path() { | ||
let mut env_path_list = internal::env::get_env_path_list()?; | ||
let config = session.config(); | ||
let mut app_path = config.root_path().join("apps"); | ||
app_path.push(package.name()); | ||
|
||
if let Some(tx) = session.emitter() { | ||
let _ = tx.send(Event::PackageEnvPathRemoveStart); | ||
} | ||
|
||
let version = if config.no_junction() { | ||
package.installed_version().unwrap() | ||
} else { | ||
"current" | ||
}; | ||
|
||
let paths = env_add_path | ||
.into_iter() | ||
.map(|p| { | ||
internal::path::normalize_path(app_path.join(version).join(p)) | ||
.to_str() | ||
.unwrap() | ||
.to_owned() | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
env_path_list.retain(|p| !paths.contains(p)); | ||
|
||
internal::env::set("PATH", &env_path_list.join(";"))?; | ||
|
||
if let Some(tx) = session.emitter() { | ||
let _ = tx.send(Event::PackageEnvPathRemoveDone); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.