diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index 43b1972..4b6662c 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -41,7 +41,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes if not exists(directory) or not isdir(directory): raise EnvironmentError('"{}" is not a directory!'.format(directory)) if self.allowed_directories: - if realpath(directory) not in self._allowed_directories: + if not self._is_whitelisted(directory): raise EnvironmentError('Directory "{}" is not in whitelist!'.format(directory)) self._workdir = directory @@ -67,6 +67,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes def files(self): return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True) if isfile(file) and + self._is_whitelisted(file) and not any(fnmatchcase(file, blacklisted) for blacklisted in self.exclude)] @property @@ -79,6 +80,9 @@ class FileManager: # pylint: disable=too-many-instance-attributes with open(self._filepath(self.filename), 'w', errors='surrogateescape') as ofile: ofile.write(value) + def _is_whitelisted(self, file): + return any(realpath(file).startswith(allowed_dir) for allowed_dir in self.allowed_directories) + def _filepath(self, filename): return join(self._workdir, filename)