summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2014-02-09 12:37:14 +0000
committerJannis Leidel <jannis@leidel.info>2014-02-09 12:39:20 +0000
commit5cc0555603167c7532b7b714e2672687da8f106e (patch)
tree0bf2b356d89aca059737134d9beaf1b70e460ed7 /django
parent9c4ad454d18816d418b0bd31be91fae16c795f15 (diff)
Fixed #21482 -- Uplifted restriction of collectstatic using symlink option in Windows NT 6.
Original patch by Vajrasky Kok. Reviewed by Florian Apolloner, Aymeric Augustin.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/staticfiles/management/commands/collectstatic.py22
-rw-r--r--django/utils/_os.py22
2 files changed, 36 insertions, 8 deletions
diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
index d16dab540c..02e95d56b9 100644
--- a/django/contrib/staticfiles/management/commands/collectstatic.py
+++ b/django/contrib/staticfiles/management/commands/collectstatic.py
@@ -1,7 +1,6 @@
from __future__ import unicode_literals
import os
-import sys
from collections import OrderedDict
from optparse import make_option
@@ -82,12 +81,8 @@ class Command(NoArgsCommand):
Split off from handle_noargs() to facilitate testing.
"""
- if self.symlink:
- if sys.platform == 'win32':
- raise CommandError("Symlinking is not supported by this "
- "platform (%s)." % sys.platform)
- if not self.local:
- raise CommandError("Can't symlink to a remote destination.")
+ if self.symlink and not self.local:
+ raise CommandError("Can't symlink to a remote destination.")
if self.clear:
self.clear_dir('')
@@ -279,7 +274,18 @@ class Command(NoArgsCommand):
os.makedirs(os.path.dirname(full_path))
except OSError:
pass
- os.symlink(source_path, full_path)
+ try:
+ os.symlink(source_path, full_path)
+ except AttributeError:
+ import platform
+ raise CommandError("Symlinking is not supported by Python %s." %
+ platform.python_version())
+ except NotImplementedError:
+ import platform
+ raise CommandError("Symlinking is not supported in this "
+ "platform (%s)." % platform.platform())
+ except OSError as e:
+ raise CommandError(e)
if prefixed_path not in self.symlinked_files:
self.symlinked_files.append(prefixed_path)
diff --git a/django/utils/_os.py b/django/utils/_os.py
index 1cf250e09e..93b965c7c6 100644
--- a/django/utils/_os.py
+++ b/django/utils/_os.py
@@ -1,6 +1,7 @@
import os
import stat
import sys
+import tempfile
from os.path import join, normcase, normpath, abspath, isabs, sep, dirname
from django.utils.encoding import force_text
@@ -99,3 +100,24 @@ def rmtree_errorhandler(func, path, exc_info):
os.chmod(path, stat.S_IWRITE)
# use the original function to repeat the operation
func(path)
+
+
+def symlinks_supported():
+ """
+ A function to check if creating symlinks are supported in the
+ host platform and/or if they are allowed to be created (e.g.
+ on Windows it requires admin permissions).
+ """
+ tmpdir = tempfile.mkdtemp()
+ original_path = os.path.join(tmpdir, 'original')
+ symlink_path = os.path.join(tmpdir, 'symlink')
+ os.makedirs(original_path)
+ try:
+ os.symlink(original_path, symlink_path)
+ supported = True
+ except (OSError, NotImplementedError, AttributeError):
+ supported = False
+ else:
+ os.remove(symlink_path)
+ finally:
+ return supported