Browse Source

Implement better folder checking

Fixes #2360, thanks @clinton_hall
pull/2269/head
mano3m 12 years ago
parent
commit
639d635913
  1. 39
      couchpotato/core/plugins/renamer/main.py

39
couchpotato/core/plugins/renamer/main.py

@ -3,7 +3,7 @@ from couchpotato.api import addApiView
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
from couchpotato.core.helpers.encoding import toUnicode, ss from couchpotato.core.helpers.encoding import toUnicode, ss
from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \ from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \
getImdb, link, symlink, tryInt getImdb, link, symlink, tryInt, splitString
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import Library, File, Profile, Release, \ from couchpotato.core.settings.model import Library, File, Profile, Release, \
@ -89,19 +89,38 @@ class Renamer(Plugin):
log.info('Renamer is already running, if you see this often, check the logs above for errors.') log.info('Renamer is already running, if you see this often, check the logs above for errors.')
return return
# Get movie folder to process
movie_folder = release_download and release_download.get('folder') movie_folder = release_download and release_download.get('folder')
# Check to see if the "to" folder is inside the "from" folder. # Get all folders that should not be processed
if movie_folder and not os.path.isdir(movie_folder) or not os.path.isdir(self.conf('from')) or not os.path.isdir(self.conf('to')): no_process = [self.conf('to')]
l = log.debug if movie_folder else log.error cat_list = fireEvent('category.all')
l('Both the "To" and "From" have to exist.') no_process.extend([item['destination'] for item in cat_list])
return try:
elif self.conf('from') in self.conf('to'): if Env.setting('library', section = 'manage').strip():
log.error('The "to" can\'t be inside of the "from" folder. You\'ll get an infinite loop.') no_process.extend(splitString(Env.setting('library', section = 'manage'), '::'))
except:
pass
# Check to see if the no_process folders are inside the "from" folder.
if not os.path.isdir(self.conf('from')) or not os.path.isdir(self.conf('to')):
log.error('Both the "To" and "From" have to exist.')
return return
elif movie_folder and movie_folder in [self.conf('to'), self.conf('from')]: else:
log.error('The "to" and "from" folders can\'t be inside of or the same as the provided movie folder.') for item in no_process:
if self.conf('from') in item:
log.error('To protect your data, the movie libraries can\'t be inside of or the same as the "from" folder.')
return
# Check to see if the no_process folders are inside the provided movie_folder
if movie_folder and not os.path.isdir(movie_folder):
log.error('The provided movie folder %s does not exist.', movie_folder)
return return
elif movie_folder:
for item in no_process:
if movie_folder in item:
log.error('To protect your data, the movie libraries can\'t be inside of or the same as the provided movie folder.')
return
# Make sure a checkSnatched marked all downloads/seeds as such # Make sure a checkSnatched marked all downloads/seeds as such
if not release_download and self.conf('run_every') > 0: if not release_download and self.conf('run_every') > 0:

Loading…
Cancel
Save