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

login
register
mail settings
Submitter Augie Fackler
Date Dec. 1, 2015, 8:01 p.m.
Message ID <65b799ebb8bf1848fe75.1449000076@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/11730/
State Accepted
Headers show

Comments

Augie Fackler - Dec. 1, 2015, 8:01 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1449000064 18000
#      Tue Dec 01 15:01:04 2015 -0500
# Node ID 65b799ebb8bf1848fe7556d5076c5683034daf1d
# Parent  fc7e6bc8faf97d0de1941d78e4b83150f8033ea5
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.
Pierre-Yves David - Dec. 2, 2015, 6:59 p.m.
On 12/01/2015 12:01 PM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1449000064 18000
> #      Tue Dec 01 15:01:04 2015 -0500
> # Node ID 65b799ebb8bf1848fe7556d5076c5683034daf1d
> # Parent  fc7e6bc8faf97d0de1941d78e4b83150f8033ea5
> posix: work around "posix" systems without os.link available (issue4974)

This patch have been pushed tot he clowncopter by a veery sad panda.

Patch

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -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