crosslink issue on linux, and cleanup entire dir (#177)

* crosslink issue on linux, and cleanup entire dir

* moved copy_dir_all to rust

* using dircpy instead of diy due to complications

* refactor: move copy_dir_all to jarvis plugin

All commands are in jarvis plugin, this is more organized.
And this API will be exposed to extensions.

---------

Co-authored-by: Huakun Shen <huakun.shen@huakunshen.com>
This commit is contained in:
Luca Giannini 2025-02-22 08:58:41 +01:00 committed by GitHub
parent a0bd2d8573
commit 872b601338
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 130 additions and 5 deletions

44
Cargo.lock generated
View File

@ -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",

View File

@ -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 }

View File

@ -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

View File

@ -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 })
}

View File

@ -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,

View File

@ -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"

View File

@ -50,6 +50,7 @@ const COMMANDS: &[&str] = &[
"decompress_tarball",
"compress_tarball",
"unzip",
"copy_dir_all",
/* -------------------------------------------------------------------------- */
/* File Search */
/* -------------------------------------------------------------------------- */

View File

@ -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",

View File

@ -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"]

View File

@ -154,6 +154,32 @@ Denies the compress_tarball command without any pre-configured scope.
<tr>
<td>
`jarvis:allow-copy-dir-all`
</td>
<td>
Enables the copy_dir_all command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`jarvis:deny-copy-dir-all`
</td>
<td>
Denies the copy_dir_all command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`jarvis:allow-create-command`
</td>

View File

@ -349,6 +349,16 @@
"type": "string",
"const": "deny-compress-tarball"
},
{
"description": "Enables the copy_dir_all command without any pre-configured scope.",
"type": "string",
"const": "allow-copy-dir-all"
},
{
"description": "Denies the copy_dir_all command without any pre-configured scope.",
"type": "string",
"const": "deny-copy-dir-all"
},
{
"description": "Enables the create_command command without any pre-configured scope.",
"type": "string",

View File

@ -35,3 +35,11 @@ pub async fn unzip(
) -> Result<(), String> {
utils::fs::unzip(&path, &destination_folder, overwrite).map_err(|err| err.to_string())
}
#[tauri::command]
/// copy one dir to another (or location)
///
/// uses the [`dircpy`](https://crates.io/crates/dircpy) crate for recursive directory copying.
pub async fn copy_dir_all(from: String, to: String) -> Result<(), String> {
dircpy::copy_dir(from, to).map_err(|e| e.to_string())
}

View File

@ -115,6 +115,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
commands::fs::decompress_tarball,
commands::fs::compress_tarball,
commands::fs::unzip,
commands::fs::copy_dir_all,
/* ------------------------------- file search ------------------------------ */
commands::file_search::file_search,
/* ------------------------------- extensions ------------------------------- */