Code

Ticket #4282: django-4282.diff

File django-4282.diff, 1.5 KB (added by Fredrik Lundh <fredrik@…>, 7 years ago)

Updated patch, against revision 6281.

Line 
1Index: django/core/management/base.py
2===================================================================
3--- django/core/management/base.py      (revision 6281)
4+++ django/core/management/base.py      (working copy)
5@@ -165,7 +165,6 @@
6 def copy_helper(style, app_or_project, name, directory, other_name=''):
7     import django
8     import re
9-    import shutil
10     other = {'project': 'app', 'app': 'project'}[app_or_project]
11     if not re.search(r'^\w+$', name): # If it's not a valid directory name.
12         raise CommandError("%r is not a valid %s name. Please use only numbers, letters and underscores." % (name, app_or_project))
13@@ -198,7 +197,7 @@
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@@ -214,3 +213,11 @@
23         new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
24         os.chmod(filename, new_permissions)
25 
26+def _copy_execute_permission(path_old, path_new):
27+    import stat
28+    if hasattr(os, 'chmod'):
29+       st = os.stat(path_old)
30+       mode = stat.S_IMODE(st.st_mode)
31+       if mode & 0111:
32+           new_mode = stat.S_IMODE(os.stat(path_new).st_mode)
33+           os.chmod(path_new, new_mode | 0111)