summaryrefslogtreecommitdiff
path: root/pygnulib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2022-08-03 14:37:12 +0200
committerBruno Haible <bruno@clisp.org>2022-08-03 14:37:12 +0200
commit22ad26c0b2d86acb21a1eab665ac9d25a2a58d21 (patch)
tree427b999f32b2b98c2789f93f73b8bf8cfee20a98 /pygnulib
parented7b3d9bb825644533235fcc636134bc8bc368f2 (diff)
downloadgnulib-22ad26c0b2d86acb21a1eab665ac9d25a2a58d21.tar.gz
gnulib-tool.py: Follow gnulib-tool changes, part 20.
Follow gnulib-tool changes 2016-01-15 Paul Eggert <eggert@cs.ucla.edu> gnulib-tool: don't assume ln -s works 2016-01-24 Paul Eggert <eggert@cs.ucla.edu> gnulib-tool: don't give up on ln -s so easily 2017-06-08 Bruno Haible <bruno@clisp.org> gnulib-tool: Fix bug in func_ln_s, from 2016-01-15. * pygnulib/constants.py (symlink_relative): New function. (link_relative): Use it instead of os.symlink.
Diffstat (limited to 'pygnulib')
-rw-r--r--pygnulib/constants.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index 34c17aec46..ca5e3f79aa 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -338,6 +338,26 @@ def movefile(src, dest):
os.remove(src)
+def symlink_relative(src, dest):
+ '''Like ln -s, except use cp -p if ln -s fails.
+ src is either absolute or relative to the directory of dest.'''
+ try:
+ os.symlink(src, dest)
+ except PermissionError:
+ sys.stderr.write('%s: ln -s failed; falling back on cp -p\n' % APP['name'])
+ if src.startswith('/') or (len(src) >= 2 and src[1] == ':'):
+ # src is absolute.
+ cp_src = src
+ else:
+ # src is relative to the directory of dest.
+ last_slash = dest.rfind('/')
+ if last_slash >= 0:
+ cp_src = joinpath(dest[0:last_slash-1], src)
+ else:
+ cp_src = src
+ copyfile2(cp_src, dest)
+
+
def link_relative(src, dest):
'''Like ln -s, except that src is given relative to the current directory
(or absolute), not given relative to the directory of dest.'''
@@ -348,17 +368,17 @@ def link_relative(src, dest):
raise TypeError(
'dest must be a string, not %s' % (type(dest).__name__))
if src.startswith('/') or (len(src) >= 2 and src[1] == ':'):
- os.symlink(src, dest)
+ symlink_relative(src, dest)
else: # if src is not absolute
if dest.startswith('/') or (len(dest) >= 2 and dest[1] == ':'):
cwd = os.getcwd()
- os.symlink(joinpath(cwd, src), dest)
+ symlink_relative(joinpath(cwd, src), dest)
else: # if dest is not absolute
destdir = os.path.dirname(dest)
if not destdir:
destdir = '.'
src = relativize(destdir, src)
- os.symlink(src, dest)
+ symlink_relative(src, dest)
def link_if_changed(src, dest):