posix: work around "posix" systems without os.link available (issue4974)

Some platforms (see bug, notably a terminal emulator on Android) ship
with os.link removed from Python to try and cater to other tools that
expect os.link to exist iff hardlinks are supported on that
platform. As a workaround for this madness, include a fallback path
for when we're on a "posix" platform but lack os.link.
This commit is contained in:
Augie Fackler 2015-12-04 15:59:46 -05:00
parent 4777cbdc66
commit 85e62f1eda

View File

@ -29,7 +29,16 @@ from . import (
posixfile = open
normpath = os.path.normpath
samestat = os.path.samestat
oslink = os.link
try:
oslink = os.link
except AttributeError:
# Some platforms build Python without os.link on systems that are
# vaguely unix-like but don't have hardlink support. For those
# poor souls, just say we tried and that it failed so we fall back
# to copies.
def oslink(src, dst):
raise OSError(errno.EINVAL,
'hardlinks not supported: %s to %s' % (src, dst))
unlink = os.unlink
rename = os.rename
removedirs = os.removedirs