Skip to content

Commit

Permalink
fix: calculate interested pieces by range (dragonflyoss#251)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Feb 5, 2024
1 parent b8db169 commit b422d8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ async fn proxy_http_by_dfdaemon(
}

info!("copy finished");
if let Err(err) = writer.flush().await {
error!("writer flush error: {}", err);
}
});

Ok(response)
Expand Down Expand Up @@ -483,7 +486,7 @@ fn make_response_headers(
format!(
"bytes {}-{}/{}",
range.start,
range.start + range.length - 1,
range.start + range.length,
download_task_started_response.content_length
),
);
Expand Down
28 changes: 13 additions & 15 deletions src/task/piece.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,22 @@ impl Piece {
}

// If offset is greater than range.start + range.length, break the loop.
if offset < range.start + range.length {
if offset >= range.start + range.length {
break;
}

if offset > range.start {
pieces.push(metadata::Piece {
number: number as u32,
offset,
length: piece_length,
digest: "".to_string(),
parent_id: None,
uploading_count: 0,
uploaded_count: 0,
updated_at: Utc::now().naive_utc(),
created_at: Utc::now().naive_utc(),
finished_at: None,
});
}
pieces.push(metadata::Piece {
number: number as u32,
offset,
length: piece_length,
digest: "".to_string(),
parent_id: None,
uploading_count: 0,
uploaded_count: 0,
updated_at: Utc::now().naive_utc(),
created_at: Utc::now().naive_utc(),
finished_at: None,
});

offset = (number + 1) * piece_length;
number += 1;
Expand Down

0 comments on commit b422d8e

Please sign in to comment.