mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #32604 -- Made file upload respect group id when uploading to a temporary file.
This commit is contained in:
parent
b8759093d8
commit
884b4c27f5
@ -339,9 +339,21 @@ class FileSystemStorage(Storage):
|
|||||||
|
|
||||||
# Ensure the saved path is always relative to the storage root.
|
# Ensure the saved path is always relative to the storage root.
|
||||||
name = os.path.relpath(full_path, self.location)
|
name = os.path.relpath(full_path, self.location)
|
||||||
|
# Ensure the moved file has the same gid as the storage root.
|
||||||
|
self._ensure_location_group_id(full_path)
|
||||||
# Store filenames with forward slashes, even on Windows.
|
# Store filenames with forward slashes, even on Windows.
|
||||||
return str(name).replace("\\", "/")
|
return str(name).replace("\\", "/")
|
||||||
|
|
||||||
|
def _ensure_location_group_id(self, full_path):
|
||||||
|
if os.name == "posix":
|
||||||
|
file_gid = os.stat(full_path).st_gid
|
||||||
|
location_gid = os.stat(self.location).st_gid
|
||||||
|
if file_gid != location_gid:
|
||||||
|
try:
|
||||||
|
os.chown(full_path, uid=-1, gid=location_gid)
|
||||||
|
except PermissionError:
|
||||||
|
pass
|
||||||
|
|
||||||
def delete(self, name):
|
def delete(self, name):
|
||||||
if not name:
|
if not name:
|
||||||
raise ValueError("The name must be given to delete().")
|
raise ValueError("The name must be given to delete().")
|
||||||
|
Loading…
Reference in New Issue
Block a user