From 1b05bc9ed221b5684a0b579d1e0dd9de4c362d0e Mon Sep 17 00:00:00 2001 From: shypike Date: Mon, 12 Aug 2013 22:18:13 +0200 Subject: [PATCH] Use ".admin" instead of "__ADMIN__" as job admin folder to support some non-standard Unix systems. ".admin" will be treated as a hidden folder by non-Windows systems, avoiding a problem with wildcard expansion for par2cmdline on some Unix systems. --- sabnzbd/api.py | 4 ++-- sabnzbd/constants.py | 3 ++- sabnzbd/misc.py | 23 ++++++++++++++++++++--- sabnzbd/nzbqueue.py | 6 +++--- sabnzbd/nzbstuff.py | 8 ++++---- sabnzbd/postproc.py | 4 ++-- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/sabnzbd/api.py b/sabnzbd/api.py index edd0da6..f94da75 100644 --- a/sabnzbd/api.py +++ b/sabnzbd/api.py @@ -52,7 +52,7 @@ from sabnzbd.utils.json import JsonWriter from sabnzbd.utils.pathbrowser import folders_at_path from sabnzbd.misc import loadavg, to_units, diskfree, disktotal, get_ext, \ get_filename, int_conv, globber, time_format, remove_all, \ - starts_with_path, cat_convert + starts_with_path, cat_convert, job_admin_dir from sabnzbd.encoding import xml_name, unicoder, special_fixer, platform_encode, html_escape from sabnzbd.postproc import PostProcessor from sabnzbd.articlecache import ArticleCache @@ -1756,7 +1756,7 @@ def build_history(start=None, limit=None, verbose=False, verbose_list=None, sear path not in retry_folders and \ starts_with_path(path, cfg.download_dir.get_path()) and \ os.path.exists(path)) and \ - not bool(globber(os.path.join(path, JOB_ADMIN), 'SABnzbd_n*')) \ + not bool(globber(job_admin_dir(path), 'SABnzbd_n*')) \ ) if item['retry']: retry_folders.append(path) diff --git a/sabnzbd/constants.py b/sabnzbd/constants.py index 7e12ddf..184387e 100644 --- a/sabnzbd/constants.py +++ b/sabnzbd/constants.py @@ -62,7 +62,8 @@ BOOKMARK_FILE_NAME = 'bookmarks.sab' SCAN_FILE_NAME = 'watched_data.sab' TERM_FLAG_FILE = 'running.sab' FUTURE_Q_FOLDER = 'future' -JOB_ADMIN = '__ADMIN__' +JOB_ADMIN = '.admin' +JOB_ADMIN_OLD = '__ADMIN__' VERIFIED_FILE = '__verified__' QCHECK_FILE = '__skip_qcheck__' RENAMES_FILE = '__renames__' diff --git a/sabnzbd/misc.py b/sabnzbd/misc.py index 7a2f5fb..3a7c105 100644 --- a/sabnzbd/misc.py +++ b/sabnzbd/misc.py @@ -39,7 +39,7 @@ except: import sabnzbd from sabnzbd.decorators import synchronized -from sabnzbd.constants import DEFAULT_PRIORITY, FUTURE_Q_FOLDER, JOB_ADMIN, GIGI, Status, MEBI +from sabnzbd.constants import DEFAULT_PRIORITY, FUTURE_Q_FOLDER, JOB_ADMIN, JOB_ADMIN_OLD, GIGI, Status, MEBI import sabnzbd.config as config import sabnzbd.cfg as cfg from sabnzbd.encoding import unicoder, latin1 @@ -268,7 +268,7 @@ def sanitize_foldername(name): #------------------------------------------------------------------------------ def flag_file(path, flag, create=False): """ Create verify flag file or return True if it already exists """ - path = os.path.join(path, JOB_ADMIN) + path = job_admin_dir(path) path = os.path.join(path, flag) if create: try: @@ -906,7 +906,7 @@ def get_admin_path(newstyle, name, future): if future: return os.path.join(cfg.admin_dir.get_path(), FUTURE_Q_FOLDER) else: - return os.path.join(os.path.join(cfg.download_dir.get_path(), name), JOB_ADMIN) + return job_admin_dir(os.path.join(cfg.download_dir.get_path(), name)) else: return cfg.cache_dir.get_path() @@ -1380,3 +1380,20 @@ def set_permissions(path, recursive=True): set_chmod(path, umask, report) else: set_chmod(path, umask_file, report) + + +def job_admin_dir(folder): + """ Return appropriate admin folder name """ + oldpath = os.path.join(folder, JOB_ADMIN_OLD) + newpath = os.path.join(folder, JOB_ADMIN) + if not os.path.isdir(oldpath): + return newpath + if os.path.isdir(oldpath): + if sabnzbd.WIN32: + # Avoid renames when on Windows, just use old name + return oldpath + else: + logging.debug('Rename old admin path to new admin path: %s to %s', oldpath, newpath) + renamer(oldpath, newpath) + return newpath + return newpath diff --git a/sabnzbd/nzbqueue.py b/sabnzbd/nzbqueue.py index 2f6e194..c3ee5d8 100644 --- a/sabnzbd/nzbqueue.py +++ b/sabnzbd/nzbqueue.py @@ -27,12 +27,12 @@ import datetime import sabnzbd from sabnzbd.trylist import TryList from sabnzbd.nzbstuff import NzbObject -from sabnzbd.misc import exit_sab, cat_to_opts, \ +from sabnzbd.misc import exit_sab, cat_to_opts, job_admin_dir, \ get_admin_path, remove_all, globber from sabnzbd.panic import panic_queue import sabnzbd.database as database from sabnzbd.decorators import NZBQUEUE_LOCK, synchronized, synchronized_CV -from sabnzbd.constants import QUEUE_FILE_NAME, QUEUE_VERSION, FUTURE_Q_FOLDER, JOB_ADMIN, \ +from sabnzbd.constants import QUEUE_FILE_NAME, QUEUE_VERSION, FUTURE_Q_FOLDER, \ LOW_PRIORITY, NORMAL_PRIORITY, HIGH_PRIORITY, TOP_PRIORITY, \ REPAIR_PRIORITY, STOP_PRIORITY, VERIFIED_FILE, \ PNFO_BYTES_FIELD, PNFO_BYTES_LEFT_FIELD, Status @@ -155,7 +155,7 @@ class NzbQueue(TryList): return not bool([True for x in verified if not verified[x]]) name = os.path.basename(folder) - path = os.path.join(folder, JOB_ADMIN) + path = job_admin_dir(folder) if hasattr(new_nzb, 'filename'): filename = new_nzb.filename else: diff --git a/sabnzbd/nzbstuff.py b/sabnzbd/nzbstuff.py index 453fecf..3fed597 100644 --- a/sabnzbd/nzbstuff.py +++ b/sabnzbd/nzbstuff.py @@ -34,14 +34,14 @@ except ImportError: # SABnzbd modules import sabnzbd -from sabnzbd.constants import sample_match, GIGI, ATTRIB_FILE, JOB_ADMIN, \ +from sabnzbd.constants import sample_match, GIGI, ATTRIB_FILE, \ DEFAULT_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY, \ HIGH_PRIORITY, PAUSED_PRIORITY, TOP_PRIORITY, DUP_PRIORITY, \ RENAMES_FILE, Status from sabnzbd.misc import to_units, cat_to_opts, cat_convert, sanitize_foldername, \ get_unique_path, get_admin_path, remove_all, format_source_url, \ sanitize_filename, globber, sanitize_foldername, int_conv, \ - set_permissions + set_permissions, job_admin_dir import sabnzbd.cfg as cfg from sabnzbd.trylist import TryList from sabnzbd.encoding import unicoder, platform_encode, latin1, name_fixer @@ -670,7 +670,7 @@ class NzbObject(TryList): # Determine "incomplete" folder wdir = os.path.join(cfg.download_dir.get_path(), self.work_name) - adir = os.path.join(wdir, JOB_ADMIN) + adir = job_admin_dir(wdir) # Duplicate checking, needs to be done before the backup duplicate = (not reuse) and nzb and dup_check and sabnzbd.backup_exists(filename) @@ -681,7 +681,7 @@ class NzbObject(TryList): else: wdir = get_unique_path(wdir, create_dir=True) set_permissions(wdir) - adir = os.path.join(wdir, JOB_ADMIN) + adir = job_admin_dir(wdir) if not os.path.exists(adir): os.mkdir(adir) diff --git a/sabnzbd/postproc.py b/sabnzbd/postproc.py index 10d5af2..2791573 100644 --- a/sabnzbd/postproc.py +++ b/sabnzbd/postproc.py @@ -36,7 +36,7 @@ from sabnzbd.misc import real_path, get_unique_path, create_dirs, move_to_path, set_permissions, cleanup_empty_directories from sabnzbd.tvsort import Sorter from sabnzbd.constants import REPAIR_PRIORITY, TOP_PRIORITY, POSTPROC_QUEUE_FILE_NAME, \ - POSTPROC_QUEUE_VERSION, sample_match, JOB_ADMIN, Status, VERIFIED_FILE + POSTPROC_QUEUE_VERSION, sample_match, Status, VERIFIED_FILE, JOB_ADMIN, JOB_ADMIN_OLD from sabnzbd.encoding import TRANS, unicoder from sabnzbd.newzbin import Bookmarks import sabnzbd.emailer as emailer @@ -351,7 +351,7 @@ def process_job(nzo): nzo.status = Status.MOVING nzo.set_action_line(T('Moving'), '...') for root, dirs, files in os.walk(workdir): - if not root.endswith(JOB_ADMIN): + if not root.endswith(JOB_ADMIN) and not root.endswith(JOB_ADMIN_OLD): for file_ in files: path = os.path.join(root, file_) new_path = path.replace(workdir, tmp_workdir_complete)