r100 - in /debtorrent/branches/http-listen/DebTorrent: BT1/FileSelector.py download_bt1.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Wed Jun 13 06:33:17 UTC 2007


Author: camrdale-guest
Date: Wed Jun 13 06:33:07 2007
New Revision: 100

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=100
Log:
Fix resuming of downloads (broken due to default of all files disabled).

Modified:
    debtorrent/branches/http-listen/DebTorrent/BT1/FileSelector.py
    debtorrent/branches/http-listen/DebTorrent/download_bt1.py

Modified: debtorrent/branches/http-listen/DebTorrent/BT1/FileSelector.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/http-listen/DebTorrent/BT1/FileSelector.py?rev=100&op=diff
==============================================================================
--- debtorrent/branches/http-listen/DebTorrent/BT1/FileSelector.py (original)
+++ debtorrent/branches/http-listen/DebTorrent/BT1/FileSelector.py Wed Jun 13 06:33:07 2007
@@ -15,14 +15,14 @@
 
 class FileSelector:
     def __init__(self, files, piece_lengths, bufferdir,
-                 storage, storagewrapper, sched, failfunc):
+                 storage, storagewrapper, sched, picker, failfunc):
         self.files = files
         self.storage = storage
         self.storagewrapper = storagewrapper
         self.sched = sched
         self.failfunc = failfunc
         self.downloader = None
-        self.picker = None
+        self.picker = picker
 
         storage.set_bufferdir(bufferdir)
         
@@ -66,13 +66,12 @@
 #           print_exc()            
             return False
         try:
-            files_updated = False
             for f in xrange(self.numfiles):
                 if new_priority[f] < 0:
                     self.storage.disable_file(f)
-                    files_updated = True
-            if files_updated:
-                self.storage.reset_file_status()
+                else:
+                    self.storage.enable_file(f)
+            self.storage.reset_file_status()
             self.new_priority = new_priority
         except (IOError, OSError), e:
             self.failfunc("can't open partial file for "
@@ -97,10 +96,10 @@
         new_piece_priority = self._get_piece_priority_list(self.new_priority)
         self.storagewrapper.reblock([i == -1 for i in new_piece_priority])
         self.new_partials = self.storagewrapper.unpickle(d, pieces)
-
-
-    def tie_in(self, picker, cancelfunc, requestmorefunc, rerequestfunc):
-        self.picker = picker
+        self.piece_priority = self._initialize_piece_priority(self.new_priority)
+
+
+    def tie_in(self, cancelfunc, requestmorefunc, rerequestfunc):
         self.cancelfunc = cancelfunc
         self.requestmorefunc = requestmorefunc
         self.rerequestfunc = rerequestfunc
@@ -199,6 +198,18 @@
                 l[i] = min(l[i],file_priority_list[f])
         return l
         
+
+    def _initialize_piece_priority(self, new_priority):
+        was_complete = self.storagewrapper.am_I_complete()
+        new_piece_priority = self._get_piece_priority_list(new_priority)
+        pieces = range(self.numpieces)
+        shuffle(pieces)
+        for piece in pieces:
+            self.picker.set_priority(piece,new_piece_priority[piece])
+        self.storagewrapper.reblock([i == -1 for i in new_piece_priority])
+
+        return new_piece_priority        
+
 
     def _set_piece_priority(self, new_priority):
         was_complete = self.storagewrapper.am_I_complete()
@@ -233,7 +244,7 @@
         self.priority = new_priority
         if not self._initialize_files_disabled(old_priority, new_priority):
             return
-#        self.piece_priority = self._set_piece_priority(new_priority)
+        self.piece_priority = self._initialize_piece_priority(new_priority)
 
     def set_priorities_now(self, new_priority = None):
         if not new_priority:

Modified: debtorrent/branches/http-listen/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/http-listen/DebTorrent/download_bt1.py?rev=100&op=diff
==============================================================================
--- debtorrent/branches/http-listen/DebTorrent/download_bt1.py (original)
+++ debtorrent/branches/http-listen/DebTorrent/download_bt1.py Wed Jun 13 06:33:07 2007
@@ -994,7 +994,7 @@
             self.fileselector = FileSelector(self.files, self.piece_lengths,
                                              self.appdataobj.getPieceDir(self.infohash),
                                              self.storage, self.storagewrapper,
-                                             self.rawserver.add_task,
+                                             self.rawserver.add_task, self.picker,
                                              self._failed)
             if data:
                 data = data.get('resume data')
@@ -1201,8 +1201,8 @@
                 self.httpdownloader.make_download(u)
 
         if self.selector_enabled:
-            self.fileselector.tie_in(self.picker, self._cancelfunc,
-                    self._reqmorefunc, self.rerequest_ondownloadmore)
+            self.fileselector.tie_in(self._cancelfunc, self._reqmorefunc, 
+                                     self.rerequest_ondownloadmore)
             if self.priority:
                 self.fileselector.set_priorities_now(self.priority)
             self.appdataobj.deleteTorrentData(self.infohash)




More information about the Debtorrent-commits mailing list