r233 - in /debtorrent/branches/unique/DebTorrent: BT1/FileSelector.py BT1/Storage.py BT1/StorageWrapper.py download_bt1.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Mon Aug 13 22:17:46 UTC 2007
Author: camrdale-guest
Date: Mon Aug 13 22:17:46 2007
New Revision: 233
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=233
Log:
Update modules that deal with files/pieces to ignore zero length ones.
Modified:
debtorrent/branches/unique/DebTorrent/BT1/FileSelector.py
debtorrent/branches/unique/DebTorrent/BT1/Storage.py
debtorrent/branches/unique/DebTorrent/BT1/StorageWrapper.py
debtorrent/branches/unique/DebTorrent/download_bt1.py
Modified: debtorrent/branches/unique/DebTorrent/BT1/FileSelector.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/BT1/FileSelector.py?rev=233&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/BT1/FileSelector.py (original)
+++ debtorrent/branches/unique/DebTorrent/BT1/FileSelector.py Mon Aug 13 22:17:46 2007
@@ -112,7 +112,17 @@
cur_piece = 0
for file, length in files:
if not length:
- self.filepieces.append(())
+ # Assign any zero-length pieces to the empty file
+ start_piece = cur_piece
+ for cur_piece in xrange(start_piece,len(piece_lengths)):
+ if piece_lengths[cur_piece] > 0:
+ break
+ end_piece = cur_piece-1
+ if piece_lengths[cur_piece] == 0:
+ # Special case if the last file in a torrent is empty
+ end_piece = cur_piece
+ pieces = range(start_piece,end_piece+1)
+ self.filepieces.append(tuple(pieces))
else:
total += length
start_piece = cur_piece
@@ -154,7 +164,7 @@
for f in xrange(self.numfiles):
if new_priority[f] < 0:
self.storage.disable_file(f)
- else:
+ elif self.files[f][1] > 0:
self.storage.enable_file(f)
self.storage.reset_file_status()
self.new_priority = new_priority
@@ -270,7 +280,7 @@
if new_disabled[f] and not old_disabled[f]:
self.storage.disable_file(f)
files_updated = True
- if old_disabled[f] and not new_disabled[f]:
+ if old_disabled[f] and not new_disabled[f] and self.files[f][1] > 0:
self.storage.enable_file(f)
files_updated = True
except (IOError, OSError), e:
@@ -301,7 +311,7 @@
new_disabled = [p == -1 for p in new_priority]
data_to_update = []
for f in xrange(self.numfiles):
- if new_disabled[f] != old_disabled[f]:
+ if new_disabled[f] != old_disabled[f] and self.files[f][1] > 0:
data_to_update.extend(self.storage.get_piece_update_list(f))
buffer = []
for piece, start, length in data_to_update:
@@ -317,7 +327,7 @@
if new_disabled[f] and not old_disabled[f]:
self.storage.disable_file(f)
files_updated = True
- if old_disabled[f] and not new_disabled[f]:
+ if old_disabled[f] and not new_disabled[f] and self.files[f][1] > 0:
self.storage.enable_file(f)
files_updated = True
except (IOError, OSError), e:
@@ -353,7 +363,7 @@
"""
l = [-1] * self.numpieces
for f in xrange(self.numfiles):
- if file_priority_list[f] == -1:
+ if file_priority_list[f] == -1 or self.files[f][1] == 0:
continue
for i in self.filepieces[f]:
if l[i] == -1:
Modified: debtorrent/branches/unique/DebTorrent/BT1/Storage.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/BT1/Storage.py?rev=233&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/BT1/Storage.py (original)
+++ debtorrent/branches/unique/DebTorrent/BT1/Storage.py Mon Aug 13 22:17:46 2007
@@ -190,10 +190,18 @@
if length == 0:
self.file_ranges.append(None)
self.working_ranges.append([])
- if total == piece_total and cur_piece > 0:
- self.file_pieces.append((cur_piece-1, cur_piece-1))
- else:
- self.file_pieces.append((cur_piece, cur_piece))
+
+ # Assign any zero-length pieces to the empty file
+ start_piece = cur_piece
+ for cur_piece in xrange(start_piece,len(self.piece_lengths)):
+ if self.piece_lengths[cur_piece] > 0:
+ break
+ self.piece_files[cur_piece] = (0L, 0L, 0L, '')
+ end_piece = cur_piece-1
+ if self.piece_lengths[cur_piece] == 0:
+ # Special case if the last file in a torrent is empty
+ end_piece = cur_piece
+ self.file_pieces.append((start_piece, end_piece))
else:
range = (total, total + length, 0, file)
self.file_ranges.append(range)
Modified: debtorrent/branches/unique/DebTorrent/BT1/StorageWrapper.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/BT1/StorageWrapper.py?rev=233&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/BT1/StorageWrapper.py (original)
+++ debtorrent/branches/unique/DebTorrent/BT1/StorageWrapper.py Mon Aug 13 22:17:46 2007
@@ -542,6 +542,8 @@
assert not got.has_key(v)
got[v] = 1
for i in xrange(len(self.hashes)):
+ if self.piece_sizes[i] == 0:
+ continue
if self.places.has_key(i): # restored from pickled
self.check_targets[self.hashes[i]] = []
if self.places[i] == i:
@@ -874,6 +876,7 @@
"""
length = self._piecelen(index)
+ assert length > 0
l = []
x = 0
while x + self.request_size < length:
@@ -939,7 +942,7 @@
Random bits are removed from the bitfield and added to the list of haves.
@rtype: (C{string}, C{list} of C{int})
- @return: the incomplete bitfiled as a binary string, and the haves to
+ @return: the incomplete bitfield as a binary string, and the haves to
complete it
"""
@@ -1273,6 +1276,7 @@
"""
assert not self.have[index]
+ assert self.piece_sizes[index] > 0
if not self.places.has_key(index):
while self._clear_space(index):
@@ -1576,10 +1580,7 @@
Pickled data format::
- d['pieces'] = either a string containing a bitfield of complete pieces,
- or the numeric value "1" signifying a seed. If it is
- a seed, d['places'] and d['partials'] should be empty
- and needn't even exist.
+ d['pieces'] = a string containing a bitfield of complete pieces
d['partials'] = [ piece, [ offset, length... ]... ]
a list of partial data that had been previously
downloaded, plus the given offsets. Adjacent partials
@@ -1601,8 +1602,6 @@
"""
- if self.have.complete():
- return {'pieces': 1}
pieces = Bitfield(len(self.hashes))
places = []
partials = []
@@ -1659,26 +1658,20 @@
restored_partials = []
try:
- if data['pieces'] == 1: # a seed
- assert not data.get('places',None)
- assert not data.get('partials',None)
- have = Bitfield(len(self.hashes))
- for i in xrange(len(self.hashes)):
+ have = Bitfield(len(self.hashes))
+ old_have = Bitfield(len(self.hashes), data['pieces'])
+ for i in xrange(len(self.hashes)):
+ if old_have[i] and self.piece_sizes[i] > 0:
have[i] = True
- assert have.complete()
- _places = []
- _partials = []
- else:
- have = Bitfield(len(self.hashes), data['pieces'])
- _places = data['places']
- assert len(_places) % 2 == 0
- _places = [_places[x:x+2] for x in xrange(0,len(_places),2)]
- _partials = data['partials']
- assert len(_partials) % 2 == 0
- _partials = [_partials[x:x+2] for x in xrange(0,len(_partials),2)]
+ _places = data['places']
+ assert len(_places) % 2 == 0
+ _places = [_places[x:x+2] for x in xrange(0,len(_places),2)]
+ _partials = data['partials']
+ assert len(_partials) % 2 == 0
+ _partials = [_partials[x:x+2] for x in xrange(0,len(_partials),2)]
for index, place in _places:
- if place not in valid_places:
+ if place not in valid_places or self.piece_sizes[index] == 0:
continue
assert not got.has_key(index)
assert not got.has_key(place)
@@ -1705,6 +1698,8 @@
for index, plist in _partials:
assert not dirty.has_key(index)
assert not have[index]
+ if self.piece_sizes[index] == 0:
+ continue
if not places.has_key(index):
if index not in valid_places:
continue
Modified: debtorrent/branches/unique/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/download_bt1.py?rev=233&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/download_bt1.py (original)
+++ debtorrent/branches/unique/DebTorrent/download_bt1.py Mon Aug 13 22:17:46 2007
@@ -758,10 +758,13 @@
files = []
for x in self.info['files']:
- n = file
- for i in x['path']:
- n = path.join(n, i)
- files.append((n, x['length']))
+ if x['path']:
+ n = file
+ for i in x['path']:
+ n = path.join(n, i)
+ files.append((n, x['length']))
+ else:
+ files.append(('', 0L))
#Move directory creation to Storage
#make(n)
except OSError, e:
More information about the Debtorrent-commits
mailing list