Check free disk space before copying files to iPod
git-svn-id: svn://svn.berlios.de/gpodder/trunk@466 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
parent
7777799e73
commit
b164fc3c62
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Thu, 15 Nov 2007 11:07:42 +0100 <thp@perli.net>
|
||||
Check free disk space before copying files to iPod
|
||||
|
||||
* src/gpodder/libipodsync.py: Check if the iPod's filesystem has
|
||||
enough free disk space before copying files over to it, as to not
|
||||
corrupt the iTunesDB in certain situations and fail when disk is full;
|
||||
thanks to Nicolas Quienot <niqooo@gmail.com> for the bug report
|
||||
* src/gpodder/util.py: Add get_free_disk_space() function that
|
||||
calculates the free (user-available) disk space on a given path
|
||||
|
||||
Wed, 14 Nov 2007 21:55:18 +0100 <thp@perli.net>
|
||||
Add informative tooltips to channel navigator
|
||||
|
||||
|
|
|
@ -368,10 +368,22 @@ class gPodder_iPodSync( gPodderSyncMethod):
|
|||
status_text = _('Already on iPod: %s') % ( episode.title, )
|
||||
self.set_status( episode = status_text)
|
||||
return True
|
||||
|
||||
log( '(ipodsync) Adding item: %s from %s', episode.title, channel.title)
|
||||
|
||||
original_filename = str( episode.local_filename())
|
||||
local_filename = original_filename
|
||||
|
||||
# Reserve 10 MiB for iTunesDB writing (to be on the safe side)
|
||||
RESERVED_FOR_ITDB = 1024*1024*10
|
||||
space_for_track = util.get_free_disk_space(self.ipod_mount) - RESERVED_FOR_ITDB
|
||||
needed = util.calculate_size(local_filename)
|
||||
|
||||
if needed > space_for_track:
|
||||
log('Not enough space on %s: %s available, but need at least %s', self.ipod_mount, util.format_filesize(space_for_track), util.format_filesize(needed), sender = self)
|
||||
self.errors.append( _('Error copying %s: Not enough free disk space on %s') % (episode.title, self.ipod_mount))
|
||||
self.cancelled = True
|
||||
return False
|
||||
|
||||
log( '(ipodsync) Adding item: %s from %s', episode.title, channel.title)
|
||||
if libconverter.converters.has_converter( os.path.splitext( original_filename)[1][1:]):
|
||||
log('(ipodsync) Converting: %s', original_filename)
|
||||
callback_status = lambda percentage: self.set_episode_convert_status( episode.title, percentage)
|
||||
|
|
|
@ -136,6 +136,16 @@ def calculate_size( path):
|
|||
return 0L
|
||||
|
||||
|
||||
def get_free_disk_space(path):
|
||||
"""
|
||||
Calculates the free disk space available to the current user
|
||||
on the file system that contains the given path.
|
||||
"""
|
||||
s = os.statvfs(path)
|
||||
|
||||
return s.f_bavail * s.f_bsize
|
||||
|
||||
|
||||
def format_filesize( bytesize, use_si_units = False):
|
||||
"""
|
||||
Formats the given size in bytes to be human-readable,
|
||||
|
|
Loading…
Reference in New Issue