Skip to content

Commit

Permalink
Don't warn about missing dirs in autorefresh mode
Browse files Browse the repository at this point in the history
This fixes the slightly annoying behaviur in #191 but also makes
conceptual sense: in autorefresh mode files and directories can not
exist when the application starts and be added later, so it doesn't make
sense to complain about their absence on startup.
  • Loading branch information
evansd committed Sep 11, 2018
1 parent b444c9f commit 0ee3bcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions tests/test_whitenoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ def test_no_error_on_very_long_filename(self):
response = self.server.get('/blah' * 1000)
self.assertNotEqual(response.status_code, 500)

def test_warn_about_missing_directories(self):
# This is the one minor behavioural difference when autorefresh is
# enabled: we don't warn about missing directories as these can be
# created after the application is started
pass

@classmethod
def tearDownClass(cls):
super(WhiteNoiseTest, cls).tearDownClass()
Expand Down
10 changes: 5 additions & 5 deletions whitenoise/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ def add_files(self, root, prefix=None):
root = root.rstrip(os.path.sep) + os.path.sep
prefix = decode_if_byte_string(prefix)
prefix = ensure_leading_trailing_slash(prefix)
is_directory = os.path.isdir(root)
if not is_directory:
warnings.warn(u'No directory at: {}'.format(root))
if self.autorefresh:
# Later calls to `add_files` overwrite earlier ones, hence we need
# to store the list of directories in reverse order so later ones
# match first when they're checked in "autorefresh" mode
self.directories.insert(0, (root, prefix))
elif is_directory:
self.update_files_dictionary(root, prefix)
else:
if os.path.isdir(root):
self.update_files_dictionary(root, prefix)
else:
warnings.warn(u'No directory at: {}'.format(root))

def update_files_dictionary(self, root, prefix):
# Build a mapping from paths to the results of `os.stat` calls
Expand Down

0 comments on commit 0ee3bcb

Please sign in to comment.