Updated to handle sync failure when no space left

Changed sync code to check needed pace against available space and raise
error if there is not enough room for the track.  This causes the track
to be listed in the failed_sync list.  I could not get it to be in the
failed_sync list without raising an exception.  Added a new sync failed
exception.

Also changed the main gtkui code to not include the failed_sync tracks
in the list of tracks to perform post-sync processing on.  This prevents
tracks that were not copied from being marked as played.
This commit is contained in:
Aaron Wright 2013-12-19 20:01:16 -05:00
parent f69934188e
commit ce6ddb6db0
2 changed files with 12 additions and 2 deletions

View File

@ -1395,7 +1395,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
self.show_message(message, _('Device synchronization failed'), True, widget=self.labelDownloads)
# Do post-sync processing if required
for task in finished_syncs + failed_syncs:
for task in finished_syncs:
if self.config.device_sync.after_sync.mark_episodes_played:
logger.info('Marking as played on transfer: %s', task.episode.url)
task.episode.mark(is_played=True)

View File

@ -561,6 +561,15 @@ class MP3PlayerDevice(Device):
assert filename is not None
from_file = util.sanitize_encoding(filename)
# verify free space
needed = util.calculate_size(from_file)
free = self.get_free_space()
if needed > free:
d = {'path': self.destination, 'free': util.format_filesize(free), 'need': util.format_filesize(needed)}
message =_('Not enough space in %(path)s: %(free)s available, but need at least %(need)s')
raise SyncFailedException(message % d)
# get the filename that will be used on the device
to_file = self.get_episode_file_on_device(episode)
to_file = util.sanitize_encoding(os.path.join(folder, to_file))
@ -900,6 +909,7 @@ class MTPDevice(Device):
return 0
class SyncCancelledException(Exception): pass
class SyncFailedException(Exception): pass
class SyncTask(download.DownloadTask):
# An object representing the synchronization task of an episode
@ -1061,7 +1071,7 @@ class SyncTask(download.DownloadTask):
self.device.add_track(self.episode, reporthook=self.status_updated)
except Exception, e:
self.status = SyncTask.FAILED
logger.error('Download failed: %s', str(e), exc_info=True)
logger.error('Sync failed: %s', str(e), exc_info=True)
self.error_message = _('Error: %s') % (str(e),)
if self.status == SyncTask.DOWNLOADING: