From df231b595ca6016587c41348b686eaf0d244620b Mon Sep 17 00:00:00 2001 From: Oleksii Tsvietnov Date: Sun, 16 Apr 2017 23:38:55 +0200 Subject: [PATCH] Fix the check if 'output_path' is inside of 'path' The check compares path names rather than strings and ensures that a content path is not located inside an output path during the erasing --- pelican/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 70013804..fba5fd65 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -162,8 +162,16 @@ class Pelican(object): # erase the directory if it is not the source and if that's # explicitly asked - if (self.delete_outputdir and not - os.path.realpath(self.path).startswith(self.output_path)): + if (self.delete_outputdir and + # Compares two dirs similar to os.path.commonpath() from Py3.5+ + # All paths at this point are already full and normalized. + # So, we can omit unnecessary checks + os.path.join(os.path.sep, + *(_subdir1 for _subdir1, _subdir2 in + zip(self.path.split(os.path.sep), + self.output_path.split(os.path.sep)) + if _subdir1 == _subdir2 + )) != self.output_path): clean_output_dir(self.output_path, self.output_retention) for p in generators: