diff --git a/Cargo.lock b/Cargo.lock index b39534d..41c3392 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1554,6 +1554,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -1582,6 +1595,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -1864,6 +1886,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "dircpy" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a88521b0517f5f9d51d11925d8ab4523497dcf947073fa3231a311b63941131c" +dependencies = [ + "jwalk", + "log", + "walkdir", +] + [[package]] name = "dirs" version = "4.0.0" @@ -3782,6 +3815,16 @@ dependencies = [ "serde_json", ] +[[package]] +name = "jwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2735847566356cd2179a2a38264839308f7079fa96e6bd5a42d740460e003c56" +dependencies = [ + "crossbeam", + "rayon", +] + [[package]] name = "k256" version = "0.13.4" @@ -7660,6 +7703,7 @@ dependencies = [ "cocoa 0.24.1", "crypto", "db", + "dircpy", "flate2", "futures-util", "grpc", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 431c82d..5b9443a 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -59,6 +59,7 @@ obfstr = { workspace = true } base64 = { workspace = true } tauri-plugin-stronghold = "2.2.0" + [target."cfg(target_os = \"macos\")".dependencies] cocoa = "0.24.1" mac-security-rs = { workspace = true } diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index c30f386..d02f488 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -131,7 +131,7 @@ pub fn run() { .plugin(tauri_plugin_network::init()) .plugin(tauri_plugin_system_info::init()) .invoke_handler(tauri::generate_handler![ - commands::keyring::get_stronghold_key + commands::keyring::get_stronghold_key, ]); let app = builder diff --git a/packages/api/src/commands/fs.ts b/packages/api/src/commands/fs.ts index 0a01491..dec063c 100644 --- a/packages/api/src/commands/fs.ts +++ b/packages/api/src/commands/fs.ts @@ -68,3 +68,15 @@ export function unzip( overwrite: options?.overwrite ?? false }) } + +/** + * Copy directory from one location to another in tauri backend + * + * Needed as Linux cannot rename paths across different filesystems + * + * @param from Source directory + * @param to Destination directory + */ +export async function copy_dir_all(from: string, to: string) { + await invoke(generateJarvisPluginCommand("copy_dir_all"), { from, to }) +} diff --git a/packages/extension/src/install.ts b/packages/extension/src/install.ts index 4a01c3b..0b2197f 100644 --- a/packages/extension/src/install.ts +++ b/packages/extension/src/install.ts @@ -3,7 +3,7 @@ * including install, uninstall, upgrade, check app-extension compatibility, etc. */ import { isCompatible } from "@kksh/api" -import { db, decompressTarball } from "@kksh/api/commands" +import { copy_dir_all, db, decompressTarball } from "@kksh/api/commands" import type { ExtPackageJsonExtra } from "@kksh/api/models" import { SBExt } from "@kksh/supabase/models" import { greaterThan, parse as parseSemver } from "@std/semver" @@ -76,7 +76,15 @@ export async function installTarball( } } - await fs.rename(decompressDest, extInstallPath) + // copy all files from decompressDest to extInstallPat + await copy_dir_all(decompressDest, extInstallPath) + + // Clean up temp directory + // we need the actual temp dir, as decompressDest is the /tmp/uuidv4/package dir + const tempDir = await path.dirname(decompressDest) + // tempDir is "/tmp/uuidv4" + await fs.remove(tempDir, { recursive: true }) + await db.createExtension({ identifier: manifest.kunkun.identifier, version: manifest.version, diff --git a/packages/tauri-plugins/jarvis/Cargo.toml b/packages/tauri-plugins/jarvis/Cargo.toml index 27f37d6..32cd8fa 100644 --- a/packages/tauri-plugins/jarvis/Cargo.toml +++ b/packages/tauri-plugins/jarvis/Cargo.toml @@ -56,7 +56,7 @@ grpc = { workspace = true } futures-util = "0.3.31" rayon = { workspace = true } local-ip-address = "0.6.3" - +dircpy = "0.3.19" [target.'cfg(target_os = "macos")'.dependencies] tauri-icns = "0.1.0" diff --git a/packages/tauri-plugins/jarvis/build.rs b/packages/tauri-plugins/jarvis/build.rs index 2b29e07..f3bcbc4 100644 --- a/packages/tauri-plugins/jarvis/build.rs +++ b/packages/tauri-plugins/jarvis/build.rs @@ -50,6 +50,7 @@ const COMMANDS: &[&str] = &[ "decompress_tarball", "compress_tarball", "unzip", + "copy_dir_all", /* -------------------------------------------------------------------------- */ /* File Search */ /* -------------------------------------------------------------------------- */ diff --git a/packages/tauri-plugins/jarvis/permissions/all.toml b/packages/tauri-plugins/jarvis/permissions/all.toml index 011b085..3e5222d 100644 --- a/packages/tauri-plugins/jarvis/permissions/all.toml +++ b/packages/tauri-plugins/jarvis/permissions/all.toml @@ -49,9 +49,10 @@ commands.allow = [ # File System "decompress_tarball", "compress_tarball", + "copy_dir_all", + "unzip", # File Search "file_search", - "unzip", # Path "get_default_extensions_dir", "get_default_extensions_storage_dir", diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/copy_dir_all.toml b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/copy_dir_all.toml new file mode 100644 index 0000000..5199628 --- /dev/null +++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/copy_dir_all.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-copy-dir-all" +description = "Enables the copy_dir_all command without any pre-configured scope." +commands.allow = ["copy_dir_all"] + +[[permission]] +identifier = "deny-copy-dir-all" +description = "Denies the copy_dir_all command without any pre-configured scope." +commands.deny = ["copy_dir_all"] diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md b/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md index 19f9805..43a78fd 100644 --- a/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md +++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md @@ -154,6 +154,32 @@ Denies the compress_tarball command without any pre-configured scope.