Skip to content

feat: add hardlink when task is downloaded #1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions dragonfly-client/src/resource/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading