Changed the check for available space. Libtorrent automatically pauses

torrents if there is not enough disk space available.  There is now an 
available disk space check when the user tries to resume a torrent.
This commit is contained in:
Andrew Resch 2007-06-15 07:35:04 +00:00
parent 1b6205990f
commit d195907bde
1 changed files with 15 additions and 16 deletions

View File

@ -452,7 +452,18 @@ class Manager:
if (index < self.get_pref('max_active_torrents') or self.get_pref('max_active_torrents') == -1) \ if (index < self.get_pref('max_active_torrents') or self.get_pref('max_active_torrents') == -1) \
and self.get_core_torrent_state(unique_ID, efficient)['is_paused'] \ and self.get_core_torrent_state(unique_ID, efficient)['is_paused'] \
and not self.is_user_paused(unique_ID): and not self.is_user_paused(unique_ID):
deluge_core.resume(unique_ID) # Before we resume, we should check if the torrent is using Full Allocation
# and if there is enough space on to finish this file.
if self.state.torrents[unique_ID].compact == False:
torrent_state = self.get_core_torrent_state(unique_ID, efficient)
avail = self.calc_free_space(self.state.torrents[unique_ID].save_dir)
total_needed = torrent_state["total_size"] - torrent_state["total_done"]
if total_needed < avail:
# We have enough free space, so lets resume this torrent
deluge_core.resume(unique_ID)
else:
print "Not enough free space to resume this torrent!"
elif (not self.get_core_torrent_state(unique_ID, efficient)['is_paused']) and \ elif (not self.get_core_torrent_state(unique_ID, efficient)['is_paused']) and \
( (index >= self.get_pref('max_active_torrents') and \ ( (index >= self.get_pref('max_active_torrents') and \
self.get_pref('max_active_torrents') != -1 ) or \ self.get_pref('max_active_torrents') != -1 ) or \
@ -664,19 +675,7 @@ class Manager:
self.state.torrents.remove(torrent) self.state.torrents.remove(torrent)
raise e raise e
# print "Got unique ID:", unique_ID # print "Got unique ID:", unique_ID
# Now to check and see if there is enough free space for the download
size = deluge_core.get_torrent_state(unique_ID)["total_size"]
avail = self.calc_free_space(torrent.save_dir)
# print "Torrent Size", size
# print "Available Space", avail
# size = avail + 1 #debug!
if size > avail: # Not enough free space
torrent.user_paused = True
no_space = True
deluge_core.remove_torrent(unique_ID) #Remove the torrent
self.state.torrents.remove(torrent)
os.remove(torrent.filename)
raise InsufficientFreeSpaceError(avail, size)
ret = unique_ID ret = unique_ID
self.unique_IDs[unique_ID] = torrent self.unique_IDs[unique_ID] = torrent
@ -718,8 +717,8 @@ class Manager:
assert(len(self.unique_IDs) == len(self.state.queue)) assert(len(self.unique_IDs) == len(self.state.queue))
assert(len(self.unique_IDs) == deluge_core.get_num_torrents()) assert(len(self.unique_IDs) == deluge_core.get_num_torrents())
if no_space: #if no_space:
self.apply_queue() #self.apply_queue()
# Pickle the state so if we experience a crash, the latest state is available # Pickle the state so if we experience a crash, the latest state is available
print "Pickling state..." print "Pickling state..."
output = open(os.path.join(self.base_dir, STATE_FILENAME), 'wb') output = open(os.path.join(self.base_dir, STATE_FILENAME), 'wb')