Re-use existing folder names for podcasts (bug 519)

When looking for a unique foldername, reuse existing
names if they belongs to a deleted channel with a
non-existing download folder.
This commit is contained in:
Morten Nygaard Åsnes 2009-08-02 19:46:49 +02:00 committed by Thomas Perl
parent e0e127fe92
commit b35c3411f3
2 changed files with 16 additions and 4 deletions

View file

@ -576,6 +576,14 @@ class Database(object):
"""
return self.__get__("SELECT id FROM channels WHERE foldername = ?", (foldername,)) is not None
def remove_foldername_if_deleted_channel(self, foldername):
cur = self.cursor(lock=True)
self.log('Setting foldername=NULL for folder "%s"', foldername)
cur.execute('UPDATE channels SET foldername=NULL ' + \
'WHERE foldername=? AND deleted=1', (foldername,))
cur.close()
self.lock.release()
def episode_filename_exists(self, filename):
"""
Returns True if a filename for an episode exists.

View file

@ -473,11 +473,15 @@ class PodcastChannel(PodcastModelObject):
current_try = util.sanitize_filename(foldername, self.MAX_FOLDERNAME_LENGTH)
next_try_id = 2
while self.db.channel_foldername_exists(current_try):
current_try = '%s (%d)' % (foldername, next_try_id)
next_try_id += 1
while True:
if not os.path.exists(os.path.join(self.download_dir, current_try)):
self.db.remove_foldername_if_deleted_channel(current_try)
return current_try
if self.db.channel_foldername_exists(current_try):
current_try = '%s (%d)' % (foldername, next_try_id)
next_try_id += 1
else:
return current_try
def get_save_dir(self):
urldigest = hashlib.md5(self.url).hexdigest()