aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/minstall.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-08-12 01:29:00 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-08-15 04:57:23 -0700
commitd03cf0459838d0b786e5f8cc9cc2dd443dda4585 (patch)
treea02448c0410ce13fdd0b214e758c391872c0bf42 /mesonbuild/minstall.py
parent4f088365e49d28e0d413d42eb024c3ff6cbfee35 (diff)
downloadmeson-d03cf0459838d0b786e5f8cc9cc2dd443dda4585.zip
meson-d03cf0459838d0b786e5f8cc9cc2dd443dda4585.tar.gz
meson-d03cf0459838d0b786e5f8cc9cc2dd443dda4585.tar.bz2
install_subdir: Also copy dangling symlinks
Fixes https://github.com/mesonbuild/meson/issues/3914
Diffstat (limited to 'mesonbuild/minstall.py')
-rw-r--r--mesonbuild/minstall.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py
index 2c007eb..f08a6b3 100644
--- a/mesonbuild/minstall.py
+++ b/mesonbuild/minstall.py
@@ -191,12 +191,16 @@ class Installer:
def should_preserve_existing_file(self, from_file, to_file):
if not self.options.only_changed:
return False
+ # Always replace danging symlinks
+ if os.path.islink(from_file) and not os.path.isfile(from_file):
+ return False
from_time = os.stat(from_file).st_mtime
to_time = os.stat(to_file).st_mtime
return from_time <= to_time
def do_copyfile(self, from_file, to_file):
- if not os.path.isfile(from_file):
+ outdir = os.path.split(to_file)[0]
+ if not os.path.isfile(from_file) and not os.path.islink(from_file):
raise RuntimeError('Tried to install something that isn\'t a file:'
'{!r}'.format(from_file))
# copyfile fails if the target file already exists, so remove it to
@@ -210,11 +214,13 @@ class Installer:
append_to_log(self.lf, '# Preserving old file %s\n' % to_file)
print('Preserving existing file %s.' % to_file)
return False
- os.unlink(to_file)
- outdir = os.path.split(to_file)[0]
+ os.remove(to_file)
print('Installing %s to %s' % (from_file, outdir))
- shutil.copyfile(from_file, to_file)
- shutil.copystat(from_file, to_file)
+ if os.path.islink(from_file):
+ shutil.copy(from_file, outdir, follow_symlinks=False)
+ else:
+ shutil.copyfile(from_file, to_file)
+ shutil.copystat(from_file, to_file)
selinux_updates.append(to_file)
append_to_log(self.lf, to_file)
return True
@@ -277,7 +283,7 @@ class Installer:
if os.path.isdir(abs_dst):
print('Tried to copy file %s but a directory of that name already exists.' % abs_dst)
if os.path.exists(abs_dst):
- os.unlink(abs_dst)
+ os.remove(abs_dst)
parent_dir = os.path.dirname(abs_dst)
if not os.path.isdir(parent_dir):
os.mkdir(parent_dir)
@@ -438,7 +444,7 @@ class Installer:
try:
symlinkfilename = os.path.join(outdir, alias)
try:
- os.unlink(symlinkfilename)
+ os.remove(symlinkfilename)
except FileNotFoundError:
pass
os.symlink(to, symlinkfilename)