1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #21380 -- Added a way to set different permission for static directories.

Previously when collecting static files, the directories would receive permissions
from the global umask. Now the default permission comes from FILE_UPLOAD_DIRECTORY_PERMISSIONS
and there's an option to specify the permissions by subclassing any of the
static files storage classes and setting the directory_permissions_mode parameter.
This commit is contained in:
Vajrasky Kok
2013-11-05 18:02:54 +08:00
committed by Tim Graham
parent 42ac138009
commit 7e2d61a972
7 changed files with 77 additions and 27 deletions

View File

@@ -294,12 +294,6 @@ Type 'yes' to continue, or 'no' to cancel: """
self.log("Pretending to copy '%s'" % source_path, level=1)
else:
self.log("Copying '%s'" % source_path, level=1)
if self.local:
full_path = self.storage.path(prefixed_path)
try:
os.makedirs(os.path.dirname(full_path))
except OSError:
pass
with source_storage.open(path) as source_file:
self.storage.save(prefixed_path, source_file)
if not prefixed_path in self.copied_files:

View File

@@ -149,7 +149,8 @@ class FileSystemStorage(Storage):
Standard filesystem storage
"""
def __init__(self, location=None, base_url=None, file_permissions_mode=None):
def __init__(self, location=None, base_url=None, file_permissions_mode=None,
directory_permissions_mode=None):
if location is None:
location = settings.MEDIA_ROOT
self.base_location = location
@@ -161,6 +162,10 @@ class FileSystemStorage(Storage):
file_permissions_mode if file_permissions_mode is not None
else settings.FILE_UPLOAD_PERMISSIONS
)
self.directory_permissions_mode = (
directory_permissions_mode if directory_permissions_mode is not None
else settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS
)
def _open(self, name, mode='rb'):
return File(open(self.path(name), mode))
@@ -175,12 +180,12 @@ class FileSystemStorage(Storage):
directory = os.path.dirname(full_path)
if not os.path.exists(directory):
try:
if settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS is not None:
if self.directory_permissions_mode is not None:
# os.makedirs applies the global umask, so we reset it,
# for consistency with FILE_UPLOAD_PERMISSIONS behavior.
# for consistency with file_permissions_mode behavior.
old_umask = os.umask(0)
try:
os.makedirs(directory, settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS)
os.makedirs(directory, self.directory_permissions_mode)
finally:
os.umask(old_umask)
else: