summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateo Radman <radmanmateo@gmail.com>2022-04-07 14:24:38 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-04-11 13:32:27 +0200
commit884b4c27f506b3c29d58509fc83a35c30ea10d94 (patch)
tree5a345ced69aa5bba7a0f9d893d984359555160af
parentb8759093d8eaea32c8d177615df7de559b6571c7 (diff)
Fixed #32604 -- Made file upload respect group id when uploading to a temporary file.
-rw-r--r--django/core/files/storage.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 71cbb93cb6..2eb8d08236 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -339,9 +339,21 @@ class FileSystemStorage(Storage):
# Ensure the saved path is always relative to the storage root.
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.
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):
if not name:
raise ValueError("The name must be given to delete().")