Code

Ticket #4282: 4282_against_16741.diff

File 4282_against_16741.diff, 1.6 KB (added by baumer1122, 3 years ago)
Line 
1diff --git a/django/core/management/base.py b/django/core/management/base.py
2index 6b9ce6e..a509d6f 100644
3--- a/django/core/management/base.py
4+++ b/django/core/management/base.py
5@@ -370,7 +370,6 @@ def copy_helper(style, app_or_project, name, directory, other_name=''):
6     # other_name -- When copying an application layout, this should be the name
7     #               of the project.
8     import re
9-    import shutil
10     other = {'project': 'app', 'app': 'project'}[app_or_project]
11     if not re.search(r'^[_a-zA-Z]\w*$', name): # If it's not a valid directory name.
12         # Provide a smart error message, depending on the error.
13@@ -410,11 +409,24 @@ def copy_helper(style, app_or_project, name, directory, other_name=''):
14             fp_old.close()
15             fp_new.close()
16             try:
17-                shutil.copymode(path_old, path_new)
18+                _copy_execute_permission(path_old, path_new)
19                 _make_writeable(path_new)
20             except OSError:
21                 sys.stderr.write(style.NOTICE("Notice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.\n" % path_new))
22 
23+def _copy_execute_permission(path_old, path_new):
24+    """
25+    Copy files respecting the user's umask if supported by the OS
26+   
27+    """
28+    import stat
29+    if hasattr(os, 'chmod'):
30+        st = os.stat(path_old)
31+        mode = stat.S_IMODE(st.st_mode)
32+        if mode & 0111:
33+            new_mode = stat.S_IMODE(os.stat(path_new).st_mode)
34+            os.chmod(path_new, new_mode | 0111)
35+
36 def _make_writeable(filename):
37     """
38     Make sure that the file is writeable. Useful if our source is