Skip to content

Commit 2917d24

Browse files
committed
feat: add hardlink when task is downloaded
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent 44362c6 commit 2917d24

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
uses: dtolnay/rust-toolchain@stable
2828
with:
2929
components: rustfmt, clippy
30+
toolchain: 1.85.0
3031

3132
- name: Set up Clang
3233
uses: egor-tensin/setup-clang@v1

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
]
1313

1414
[workspace.package]
15-
version = "0.2.29"
15+
version = "0.2.30"
1616
authors = ["The Dragonfly Developers"]
1717
homepage = "https://d7y.io/"
1818
repository = "https://github.com/dragonflyoss/client.git"
@@ -22,13 +22,13 @@ readme = "README.md"
2222
edition = "2021"
2323

2424
[workspace.dependencies]
25-
dragonfly-client = { path = "dragonfly-client", version = "0.2.29" }
26-
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.29" }
27-
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.29" }
28-
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.29" }
29-
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.29" }
30-
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.29" }
31-
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.29" }
25+
dragonfly-client = { path = "dragonfly-client", version = "0.2.30" }
26+
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.30" }
27+
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.30" }
28+
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.30" }
29+
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.30" }
30+
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.30" }
31+
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.30" }
3232
dragonfly-api = "=2.1.39"
3333
thiserror = "2.0"
3434
futures = "0.3.31"

dragonfly-client/src/resource/task.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ impl Task {
131131
let task = self.storage.prepare_download_task_started(id).await?;
132132

133133
if task.content_length.is_some() && task.piece_length.is_some() {
134+
// Attempt to create a hard link from the task file to the output path.
135+
//
136+
// Behavior based on force_hard_link setting:
137+
// 1. force_hard_link is true:
138+
// - Success: Continue processing
139+
// - Failure: Return error immediately
140+
// 2. force_hard_link is false:
141+
// - Success: Continue processing
142+
// - Failure: Fall back to copying the file instead
143+
if let Some(output_path) = &request.output_path {
144+
if let Err(err) = self
145+
.storage
146+
.hard_link_task(id, Path::new(output_path.as_str()))
147+
.await
148+
{
149+
if request.force_hard_link {
150+
return Err(err);
151+
}
152+
}
153+
}
154+
134155
return Ok(task);
135156
}
136157

0 commit comments

Comments
 (0)