From 2917d24ec67b48e82fd6e8a884d364088b23fc97 Mon Sep 17 00:00:00 2001 From: Gaius Date: Mon, 19 May 2025 17:49:23 +0800 Subject: [PATCH] feat: add hardlink when task is downloaded Signed-off-by: Gaius --- .github/workflows/lint.yml | 1 + Cargo.lock | 16 ++++++++-------- Cargo.toml | 16 ++++++++-------- dragonfly-client/src/resource/task.rs | 21 +++++++++++++++++++++ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7c6df930..ed15af05 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,6 +27,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy + toolchain: 1.85.0 - name: Set up Clang uses: egor-tensin/setup-clang@v1 diff --git a/Cargo.lock b/Cargo.lock index 9fbae221..67e22130 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -953,7 +953,7 @@ dependencies = [ [[package]] name = "dragonfly-client" -version = "0.2.29" +version = "0.2.30" dependencies = [ "anyhow", "bytes", @@ -1022,7 +1022,7 @@ dependencies = [ [[package]] name = "dragonfly-client-backend" -version = "0.2.29" +version = "0.2.30" dependencies = [ "dragonfly-api", "dragonfly-client-core", @@ -1053,7 +1053,7 @@ dependencies = [ [[package]] name = "dragonfly-client-config" -version = "0.2.29" +version = "0.2.30" dependencies = [ "bytesize", "bytesize-serde", @@ -1081,7 +1081,7 @@ dependencies = [ [[package]] name = "dragonfly-client-core" -version = "0.2.29" +version = "0.2.30" dependencies = [ "headers 0.4.0", "hyper 1.6.0", @@ -1099,7 +1099,7 @@ dependencies = [ [[package]] name = "dragonfly-client-init" -version = "0.2.29" +version = "0.2.30" dependencies = [ "anyhow", "clap", @@ -1117,7 +1117,7 @@ dependencies = [ [[package]] name = "dragonfly-client-storage" -version = "0.2.29" +version = "0.2.30" dependencies = [ "bincode", "bytes", @@ -1145,7 +1145,7 @@ dependencies = [ [[package]] name = "dragonfly-client-util" -version = "0.2.29" +version = "0.2.30" dependencies = [ "base64 0.22.1", "bytesize", @@ -1560,7 +1560,7 @@ dependencies = [ [[package]] name = "hdfs" -version = "0.2.29" +version = "0.2.30" dependencies = [ "dragonfly-client-backend", "dragonfly-client-core", diff --git a/Cargo.toml b/Cargo.toml index a30f9212..92da06d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ ] [workspace.package] -version = "0.2.29" +version = "0.2.30" authors = ["The Dragonfly Developers"] homepage = "https://d7y.io/" repository = "https://github.com/dragonflyoss/client.git" @@ -22,13 +22,13 @@ readme = "README.md" edition = "2021" [workspace.dependencies] -dragonfly-client = { path = "dragonfly-client", version = "0.2.29" } -dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.29" } -dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.29" } -dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.29" } -dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.29" } -dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.29" } -dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.29" } +dragonfly-client = { path = "dragonfly-client", version = "0.2.30" } +dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.30" } +dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.30" } +dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.30" } +dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.30" } +dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.30" } +dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.30" } dragonfly-api = "=2.1.39" thiserror = "2.0" futures = "0.3.31" diff --git a/dragonfly-client/src/resource/task.rs b/dragonfly-client/src/resource/task.rs index f700d6c9..235f6c4b 100644 --- a/dragonfly-client/src/resource/task.rs +++ b/dragonfly-client/src/resource/task.rs @@ -131,6 +131,27 @@ impl Task { let task = self.storage.prepare_download_task_started(id).await?; if task.content_length.is_some() && task.piece_length.is_some() { + // Attempt to create a hard link from the task file to the output path. + // + // Behavior based on force_hard_link setting: + // 1. force_hard_link is true: + // - Success: Continue processing + // - Failure: Return error immediately + // 2. force_hard_link is false: + // - Success: Continue processing + // - Failure: Fall back to copying the file instead + if let Some(output_path) = &request.output_path { + if let Err(err) = self + .storage + .hard_link_task(id, Path::new(output_path.as_str())) + .await + { + if request.force_hard_link { + return Err(err); + } + } + } + return Ok(task); }