feat: add hardlink when task is downloaded (#1151)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2025-05-19 18:33:59 +08:00 committed by GitHub
parent 44362c6a00
commit 3811569f29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 16 deletions

View File

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

16
Cargo.lock generated
View File

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

View File

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

View File

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