mirror of
https://github.com/macports/macports-ports.git
synced 2026-07-12 18:20:25 -07:00
97 lines
2.8 KiB
Diff
97 lines
2.8 KiB
Diff
diff --git a/man/btfs.1 b/man/btfs.1
|
|
index 3dab66e..dcdb23a 100644
|
|
--- a/man/btfs.1
|
|
+++ b/man/btfs.1
|
|
@@ -45,6 +45,9 @@ maximum download rate (in kilobytes per second)
|
|
.TP
|
|
\fB\-\-max-upload-rate=\fIRATE\fR
|
|
maximum upload rate (in kilobytes per second)
|
|
+.TP
|
|
+\fB\-\-no\-prefetch\fR
|
|
+do not download files unless an application requests it
|
|
.SH EXAMPLES
|
|
mounting a torrent file:
|
|
btfs video.torrent ~/mnt
|
|
diff --git a/src/btfs.cc b/src/btfs.cc
|
|
index 4696bd1..67c39ac 100644
|
|
--- a/src/btfs.cc
|
|
+++ b/src/btfs.cc
|
|
@@ -106,7 +106,9 @@ jump(int piece, int size) {
|
|
|
|
static void
|
|
advance() {
|
|
- jump(cursor, 0);
|
|
+ if(!params.no_prefetch) {
|
|
+ jump(cursor, 0);
|
|
+ }
|
|
}
|
|
|
|
Read::Read(char *buf, int index, off_t offset, size_t size) {
|
|
@@ -118,6 +120,10 @@ 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);
|
|
@@ -182,8 +188,15 @@ int Read::read() {
|
|
// Trigger reads of finished pieces
|
|
trigger();
|
|
|
|
- // Move sliding window to first piece to serve this request
|
|
- jump(parts.front().part.piece, size());
|
|
+ if (params.no_prefetch) {
|
|
+ // Set priority of needed pieces
|
|
+ for (parts_iter i = parts.begin(); i != parts.end(); ++i) {
|
|
+ handle.piece_priority(i->part.piece, 7);
|
|
+ }
|
|
+ } else {
|
|
+ // Move sliding window to first piece to serve this request
|
|
+ jump(parts.front().part.piece, size());
|
|
+ }
|
|
|
|
while (!finished() && !failed)
|
|
// Wait for any piece to downloaded
|
|
@@ -206,6 +219,9 @@ setup() {
|
|
|
|
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());
|
|
@@ -935,6 +951,7 @@ static const struct fuse_opt btfs_opts[] = {
|
|
BTFS_OPT("--max-port=%lu", max_port, 4),
|
|
BTFS_OPT("--max-download-rate=%lu", max_download_rate, 4),
|
|
BTFS_OPT("--max-upload-rate=%lu", max_upload_rate, 4),
|
|
+ BTFS_OPT("--no-prefetch", no_prefetch, 1),
|
|
FUSE_OPT_END
|
|
};
|
|
|
|
@@ -973,6 +990,7 @@ print_help() {
|
|
printf(" --max-port=N end of listen port range\n");
|
|
printf(" --max-download-rate=N max download rate (in kB/s)\n");
|
|
printf(" --max-upload-rate=N max upload rate (in kB/s)\n");
|
|
+ printf(" --no-prefetch don't prefetch files in the background\n");
|
|
}
|
|
|
|
int
|
|
diff --git a/src/btfs.h b/src/btfs.h
|
|
index f16da78..ded0b01 100644
|
|
--- a/src/btfs.h
|
|
+++ b/src/btfs.h
|
|
@@ -131,6 +131,7 @@ struct btfs_params {
|
|
int max_download_rate;
|
|
int max_upload_rate;
|
|
const char *metadata;
|
|
+ int no_prefetch;
|
|
};
|
|
|
|
}
|