mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Check for value error caused by no valid files found with files_changed
This causes an infinite loop when in auto-reload Fix #467 Fix #451 Fix #443
This commit is contained in:
parent
8ecebc9310
commit
86da6d1f2e
2 changed files with 22 additions and 5 deletions
|
|
@ -241,10 +241,14 @@ def files_changed(path, extensions):
|
|||
yield os.stat(os.path.join(root, f)).st_mtime
|
||||
|
||||
global LAST_MTIME
|
||||
mtime = max(file_times(path))
|
||||
if mtime > LAST_MTIME:
|
||||
LAST_MTIME = mtime
|
||||
return True
|
||||
try:
|
||||
mtime = max(file_times(path))
|
||||
if mtime > LAST_MTIME:
|
||||
LAST_MTIME = mtime
|
||||
return True
|
||||
except ValueError:
|
||||
logger.info("No files found in path")
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ class TestUtils(unittest.TestCase):
|
|||
self.assertNotIn(fr_article1, index)
|
||||
|
||||
def test_files_changed(self):
|
||||
"Test if file changes are correctly detected"
|
||||
"""Test if file changes are correctly detected
|
||||
Make sure to handle not getting any files correctly"""
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), 'content')
|
||||
filename = os.path.join(path, 'article_with_metadata.rst')
|
||||
|
|
@ -90,6 +91,18 @@ class TestUtils(unittest.TestCase):
|
|||
self.assertEquals(changed, True)
|
||||
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
||||
|
||||
empty_path = os.path.join(os.path.dirname(__file__), 'empty')
|
||||
try:
|
||||
os.mkdir(empty_path)
|
||||
os.mkdir(os.path.join(empty_path, "empty_folder"))
|
||||
shutil.copy(__file__, empty_path)
|
||||
changed = utils.files_changed(empty_path, 'rst')
|
||||
self.assertFalse(changed)
|
||||
except OSError:
|
||||
self.fail("OSError Exception in test_files_changed test")
|
||||
finally:
|
||||
shutil.rmtree(empty_path, True)
|
||||
|
||||
def test_clean_output_dir(self):
|
||||
test_directory = os.path.join(os.path.dirname(__file__), 'clean_output')
|
||||
content = os.path.join(os.path.dirname(__file__), 'content')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue