summarylogtreecommitdiffstats
path: root/lt-ps-honor_system_file_allocate_all.patch
blob: e95f62ddd163663ded0db69fa0b7d1133a8297ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
--- a/src/download/download_wrapper.cc
+++ b/src/download/download_wrapper.cc
@@ -319,6 +319,8 @@ DownloadWrapper::receive_update_prioriti
       data()->mutable_high_priority()->insert((*itr)->range().first, (*itr)->range().second);
       break;
     default:
+      // Unset fallocate flag if priority of a file is Off.
+      (*itr)->unset_flags(File::flag_fallocate);
       break;
     }
   }
--- a/src/torrent/data/file_list.cc
+++ b/src/torrent/data/file_list.cc
@@ -578,7 +578,12 @@ FileList::open_file(File* node, const Pa
     return false;
   }
 
-  return node->prepare(MemoryChunk::prot_read, 0);
+  // File allocation will be done if fallocate flag is set,
+  // create zero-length file otherwise.
+  if (node->has_flags(File::flag_fallocate))
+    return node->prepare(MemoryChunk::prot_write, 0);
+  else
+    return node->prepare(MemoryChunk::prot_read, 0);
 }
 
 MemoryChunk
--- a/src/torrent/download.cc
+++ b/src/torrent/download.cc
@@ -143,9 +143,9 @@ Download::start(int flags) {
 
 //   file_list()->open(flags);
 
-  // If the FileList::open_no_create flag was not set, our new
-  // behavior is to create all zero-length files with
-  // flag_queued_create set.
+  // If the open_enable_fallocate or the FileList::open_no_create
+  // flag was not set, then create all zero-length files with
+  // flag_create_queued set.
   file_list()->open(flags & ~FileList::open_no_create);
 
   if (m_ptr->connection_type() == CONNECTION_INITIAL_SEED) {