aboutsummaryrefslogtreecommitdiff
path: root/mling/src/namespace_manager.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-07 02:25:27 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-07 02:25:27 +0800
commit81528b273c18693ebd3f05c6f8057ff8e632f4a0 (patch)
tree85026c27535337c0123d4650c844ae364bc9780a /mling/src/namespace_manager.rs
parente41e8bda221b44d09d7e93ffc43675147ab60a6d (diff)
Refactor mling to use new program architecture and install scripts
Diffstat (limited to 'mling/src/namespace_manager.rs')
-rw-r--r--mling/src/namespace_manager.rs125
1 files changed, 0 insertions, 125 deletions
diff --git a/mling/src/namespace_manager.rs b/mling/src/namespace_manager.rs
deleted file mode 100644
index d5176dd..0000000
--- a/mling/src/namespace_manager.rs
+++ /dev/null
@@ -1,125 +0,0 @@
-use std::path::PathBuf;
-
-use just_fmt::kebab_case;
-
-#[must_use]
-pub fn list_namespaces(
- show_trusted: bool,
- show_untrusted: bool,
- show_untagged: bool,
-) -> Vec<String> {
- let wdir = working_dir();
- if !wdir.exists() {
- return Vec::new();
- }
-
- let mut namespaces = Vec::new();
- let Ok(entries) = std::fs::read_dir(&wdir) else {
- return Vec::new();
- };
- for entry in entries {
- let Ok(entry) = entry else {
- continue;
- };
- let path = entry.path();
- if path.is_dir()
- && let Some(name) = path.file_name()
- && let Some(name_str) = name.to_str()
- {
- // Skip directories starting with a dot
- if name_str.starts_with('.') {
- continue;
- }
- let namespace = name_str.to_string();
- let is_trusted = is_trusted_namespace(namespace.clone());
- let is_untrusted = is_untrusted_namespace(namespace.clone());
- let is_untagged = is_untagged_namespace(namespace.clone());
-
- if (show_trusted && is_trusted)
- || (show_untrusted && is_untrusted)
- || (show_untagged && is_untagged)
- {
- namespaces.push(namespace);
- }
- }
- }
-
- namespaces
-}
-
-pub fn set_namespace_trusted(namespace: String, trusted: bool) {
- let ndir = namespace_dir(namespace);
- let trusted_file = ndir.join("TRUSTED");
- let untrusted_file = ndir.join("UNTRUSTED");
-
- if trusted {
- // Create TRUSTED file and remove UNTRUSTED if it exists
- let _ = std::fs::write(&trusted_file, "");
- let _ = std::fs::remove_file(&untrusted_file);
- } else {
- // Create UNTRUSTED file and remove TRUSTED if it exists
- let _ = std::fs::write(&untrusted_file, "");
- let _ = std::fs::remove_file(&trusted_file);
- }
-}
-
-pub fn remove_namespace(namespace: String) {
- let ndir = namespace_dir(namespace);
- if ndir.exists() {
- let _ = std::fs::remove_dir_all(&ndir);
- }
-}
-
-/// Returns the mingling data directory.
-///
-/// # Panics
-///
-/// Panics if the platform's data directory cannot be determined.
-#[must_use]
-pub fn working_dir() -> PathBuf {
- dirs::data_dir().unwrap().join("mingling")
-}
-
-#[must_use]
-pub fn namespace_dir(namespace: String) -> PathBuf {
- working_dir().join(kebab_case!(namespace))
-}
-
-#[must_use]
-pub fn is_untrusted_namespace(namespace: String) -> bool {
- let untrusted_file = namespace_dir(namespace).join("UNTRUSTED");
- untrusted_file.exists()
-}
-
-#[must_use]
-pub fn is_trusted_namespace(namespace: String) -> bool {
- let trusted = namespace_dir(namespace).join("TRUSTED");
- trusted.exists()
-}
-
-#[must_use]
-pub fn is_untagged_namespace(namespace: String) -> bool {
- let ndir = namespace_dir(namespace);
- let trusted = ndir.join("TRUSTED");
- let untrusted = ndir.join("UNTRUSTED");
- !trusted.exists() && !untrusted.exists()
-}
-
-#[must_use]
-pub fn bin_dir(namespace: String) -> PathBuf {
- namespace_dir(namespace).join("bin")
-}
-
-#[must_use]
-pub fn comp_dir(namespace: String) -> PathBuf {
- namespace_dir(namespace).join("comp")
-}
-
-#[must_use]
-pub fn exe_path(namespace: String, bin_name_without_ext: String) -> PathBuf {
- if cfg!(target_os = "windows") {
- bin_dir(namespace).join(bin_name_without_ext + ".exe")
- } else {
- bin_dir(namespace).join(bin_name_without_ext)
- }
-}