From 5c586fbf3027080de8993c5167522aa801701985 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 24 Jun 2014 10:02:14 +0200 Subject: [PATCH] Update isSubFolder test --- couchpotato/core/helpers/variable.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 66e01f55..f98adaa2 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -291,9 +291,14 @@ def dictIsSubset(a, b): return all([k in b and b[k] == v for k, v in a.items()]) +# Returns True if sub_folder is the same as or inside base_folder def isSubFolder(sub_folder, base_folder): - # Returns True if sub_folder is the same as or inside base_folder - return base_folder and sub_folder and ss(os.path.normpath(base_folder).rstrip(os.path.sep) + os.path.sep) in ss(os.path.normpath(sub_folder).rstrip(os.path.sep) + os.path.sep) + if base_folder and sub_folder: + base = sp(os.path.realpath(base_folder)) + subfolder = sp(os.path.realpath(sub_folder)) + return os.path.commonprefix([subfolder, base]) == base + + return False # From SABNZBD