diff options
author | Yuri Konotopov <ykonotopov@gnome.org> | 2022-09-14 16:24:43 +0400 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-10-24 13:54:51 +0200 |
commit | 64e5ef1f17cd18cb8ca24f4e7107dfd28c18b378 (patch) | |
tree | 892cdb18df92907297cbe20f254060e219243b04 /django/core/files/move.py | |
parent | 08c5a787262c1ae57f6517d4574b54a5fcaad124 (diff) | |
download | django-64e5ef1f17cd18cb8ca24f4e7107dfd28c18b378.tar.gz |
Fixed #29027 -- Fixed file_move_safe() crash when moving files with SELinux.
Thanks Florian Apolloner for the review.
Diffstat (limited to 'django/core/files/move.py')
-rw-r--r-- | django/core/files/move.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/django/core/files/move.py b/django/core/files/move.py index 2d71e11885..95d69f9d94 100644 --- a/django/core/files/move.py +++ b/django/core/files/move.py @@ -5,9 +5,8 @@ Move a file in the safest way possible:: >>> file_move_safe("/tmp/old_file", "/tmp/new_file") """ -import errno import os -from shutil import copystat +from shutil import copymode, copystat from django.core.files import locks @@ -82,12 +81,15 @@ def file_move_safe( try: copystat(old_file_name, new_file_name) - except PermissionError as e: + except PermissionError: # Certain filesystems (e.g. CIFS) fail to copy the file's metadata if # the type of the destination filesystem isn't the same as the source - # filesystem; ignore that. - if e.errno != errno.EPERM: - raise + # filesystem. This also happens with some SELinux-enabled systems. + # Ignore that, but try to set basic permissions. + try: + copymode(old_file_name, new_file_name) + except PermissionError: + pass try: os.remove(old_file_name) |