Skip to content

Commit

Permalink
Added check for non writable files in DATA_DIR
Browse files Browse the repository at this point in the history
This usually indicates some configuration issue, eg. celery running as
different user than wsgi. See #2400

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Nov 27, 2018
1 parent 62fda27 commit e1b0c87
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Released on October 20th 2018.
* Added translation component alerts to highlight problems with a translation.
* Expose XLIFF unit resname as context when available.
* Added support for XLIFF states.
* Added check for non writable files in DATA_DIR.

weblate 3.2.1
-------------
Expand Down
3 changes: 2 additions & 1 deletion weblate/utils/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from weblate.utils.checks import (
check_mail_connection, check_celery, check_database,
check_cache, check_settings, check_templates,
check_data_writable, check_site,
check_data_writable, check_site, check_perms,
)
from weblate.utils.fonts import check_fonts
from weblate.utils.requirements import check_requirements
Expand All @@ -49,5 +49,6 @@ def ready(self):
register(check_settings, deploy=True)
register(check_templates, deploy=True)
register(check_site, deploy=True)
register(check_perms, deploy=True)

monkey_patch_translate()
30 changes: 29 additions & 1 deletion weblate/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

from __future__ import unicode_literals, absolute_import

import os.path
from itertools import chain
import os

from celery.exceptions import TimeoutError

Expand Down Expand Up @@ -273,3 +274,30 @@ def check_site(app_configs, **kwargs):
)
)
return errors


def check_perms(app_configs=None, **kwargs):
"""Check we can write to data dir."""
errors = []
ignore = (
'.git', '.hg', '.svn',
'test-base-repo.git', 'test-base-repo.svn',
'test-repo.git', 'test-repo.svn',
)
message = 'Path {} is not writable, check your DATA_DIR settings.'
for dirpath, dirnames, filenames in os.walk(settings.DATA_DIR):
for name in ignore:
if name in dirnames:
dirnames.remove(name)
for name in chain(dirnames, filenames):
path = os.path.join(dirpath, name)
if not os.access(path, os.W_OK):
errors.append(
Critical(
message.format(path),
hint=get_doc_url('admin/install', 'file-permissions'),
id='weblate.E002',
)
)

return errors

0 comments on commit e1b0c87

Please sign in to comment.