summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMel Collins <mel@raumkraut.net>2013-05-13 13:38:53 +0200
committerTim Graham <timograham@gmail.com>2013-08-12 07:15:59 -0400
commit6bdb3b1135d1bd7b2dc24131b9d26ac19ebdba67 (patch)
tree4f9e44d7b494b737ed11d7346ff7258c182cfbb3 /django
parentab680725bfb2f0d79cff26331b30a3d583c55a80 (diff)
Fixed #13518 -- Added FILE_UPLOAD_DIRECTORY_PERMISSIONS setting
This setting does for new directories what FILE_UPLOAD_PERMISSIONS does for new files. Thanks jacob@ for the suggestion.
Diffstat (limited to 'django')
-rw-r--r--django/conf/global_settings.py5
-rw-r--r--django/core/files/storage.py11
2 files changed, 15 insertions, 1 deletions
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 19258fbcd4..95deaa8d87 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -313,6 +313,11 @@ FILE_UPLOAD_TEMP_DIR = None
# you'd pass directly to os.chmod; see http://docs.python.org/lib/os-file-dir.html.
FILE_UPLOAD_PERMISSIONS = None
+# The numeric mode to assign to newly-created directories, when uploading files.
+# The value should be a mode as you'd pass to os.chmod;
+# see http://docs.python.org/lib/os-file-dir.html.
+FILE_UPLOAD_DIRECTORY_PERMISSIONS = None
+
# Python module path where user will place custom format definition.
# The directory where this setting is pointing should contain subdirectories
# named as the locales, containing a formats.py file
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 5d301a317c..5e587da2da 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -172,7 +172,16 @@ class FileSystemStorage(Storage):
directory = os.path.dirname(full_path)
if not os.path.exists(directory):
try:
- os.makedirs(directory)
+ if settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS is not None:
+ # os.makedirs applies the global umask, so we reset it,
+ # for consistency with FILE_UPLOAD_PERMISSIONS behavior.
+ old_umask = os.umask(0)
+ try:
+ os.makedirs(directory, settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS)
+ finally:
+ os.umask(old_umask)
+ else:
+ os.makedirs(directory)
except OSError as e:
if e.errno != errno.EEXIST:
raise