Skip to content

Commit

Permalink
Device sync: Only fail if we can determine free disk space (bug 2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Dec 16, 2015
1 parent db7d9bc commit 169102d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/gpodder/opml.py
Expand Up @@ -179,7 +179,7 @@ def write( self, channels):
FREE_DISK_SPACE_AFTER = 1024*512
path = os.path.dirname(self.filename) or os.path.curdir
available = util.get_free_disk_space(path)
if available < 2*len(data)+FREE_DISK_SPACE_AFTER:
if available != -1 and available < 2*len(data)+FREE_DISK_SPACE_AFTER:
# On Windows, if we have zero bytes available, assume that we have
# not had the win32file module available + assume enough free space
if not gpodder.ui.win32 or available > 0:
Expand Down
10 changes: 8 additions & 2 deletions src/gpodder/sync.py
Expand Up @@ -281,7 +281,11 @@ def __init__(self, config,
def get_free_space(self):
# Reserve 10 MiB for iTunesDB writing (to be on the safe side)
RESERVED_FOR_ITDB = 1024*1024*10
return util.get_free_disk_space(self.mountpoint) - RESERVED_FOR_ITDB
result = util.get_free_disk_space(self.mountpoint)
if result == -1:
# Can't get free disk space
return -1
return result - RESERVED_FOR_ITDB

def open(self):
Device.open(self)
Expand Down Expand Up @@ -565,7 +569,9 @@ def add_track(self, episode,reporthook=None):
# verify free space
needed = util.calculate_size(from_file)
free = self.get_free_space()
if needed > free:
if free == -1:
logger.warn('Cannot determine free disk space on device')
elif 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)
Expand Down
4 changes: 2 additions & 2 deletions src/gpodder/util.py
Expand Up @@ -453,7 +453,7 @@ def get_free_disk_space_win32(path):
"""
if win32file is None:
# Cannot determine free disk space
return 0
return -1

drive, tail = os.path.splitdrive(path)
userFree, userTotal, freeOnDisk = win32file.GetDiskFreeSpaceEx(drive)
Expand All @@ -470,7 +470,7 @@ def get_free_disk_space(path):
"""

if not os.path.exists(path):
return 0
return -1

if gpodder.ui.win32:
return get_free_disk_space_win32(path)
Expand Down

0 comments on commit 169102d

Please sign in to comment.