Add --no-prefetch flag to disable downloading the whole torrent#83
Open
Tilo15 wants to merge 2 commits into
Open
Add --no-prefetch flag to disable downloading the whole torrent#83Tilo15 wants to merge 2 commits into
Tilo15 wants to merge 2 commits into
Conversation
added 2 commits
January 4, 2024 16:37
Contributor
|
for cases where you want to avoid downloading the rest of the file once you start reading it diff --git a/src/btfs.cc b/src/btfs.cc
index 67c39ac..81166f8 100644
--- a/src/btfs.cc
+++ b/src/btfs.cc
@@ -120,10 +120,6 @@ Read::Read(char *buf, int index, off_t offset, size_t size) {
int64_t file_size = ti->files().file_size(index);
#endif
- if(params.no_prefetch) {
- handle.file_priority(index, 1);
- }
-
while (size > 0 && offset < file_size) {
libtorrent::peer_request part = ti->map_file(index, offset,
(int) size);
@@ -217,11 +213,13 @@ setup() {
if (params.browse_only)
handle.pause();
+ if(params.no_prefetch) {
+ std::vector<libtorrent::download_priority_t> priorities(ti->num_pieces());
+ handle.prioritize_pieces(priorities);
+ }
+
for (int i = 0; i < ti->num_files(); ++i) {
std::string parent("");
- if(params.no_prefetch) {
- handle.file_priority(i, 0);
- }
#if LIBTORRENT_VERSION_NUM < 10100
char *p = strdup(ti->file_at(i).path.c_str());if you still want the file-based pre-fetch, you can change the pre-fetch flag to accept a value instead |
|
Hi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been playing with making peer-to-peer software repositories for DNF/RPM. This tool is very useful since I can create a torrent of my repository and mount it to make the repo accessible to the package manager.
I noticed in #72 that btfs by design downloads the whole torrent. In my use case, I only want the files that the package manager needs to read to be downloaded from the torrent, and it seems from that issue that other users may have similar use cases.
In this pull request I have added the
--no-prefetchflag which when used changes the behaviour of btfs in the following ways:setup()function.This means that once a file is partly read, pieces of that file only will be downloaded in the background, but the priority will still be on the parts of the file the application requested from the filesystem.
Thank you for your time and consideration.