minstall: Treat symlinks to directories as directories if follow_symlinks is enabled in do_copydir()

Fix the installation of a subdirectory that contains a symlink to a
directory, when follow_symlinks is enabled.

Currently, the following error is thrown in that case:

> IsADirectoryError: [Errno 21] Is a directory: '<path to symlink to directory>'
This commit is contained in:
André Apitzsch authored and Paolo Bonzini committed 2026-09-08 08:06:55 +02:00
1 parent c6cbfbbf68
commit 6ba8c4d628
6 files changed
+22 -3

No files matched your search

+2 -2
View File
@@ -507,13 +507,13 @@ class Installer:
exclude_dirs = {os.path.normpath(x) for x in exclude_dirs}
else:
exclude_files = exclude_dirs = set()
for root, dirs, files in os.walk(src_dir):
for root, dirs, files in os.walk(src_dir, followlinks=bool(follow_symlinks)):
assert os.path.isabs(root)
for d in dirs[:]:
abs_src = os.path.join(root, d)
filepart = os.path.relpath(abs_src, start=src_dir)
abs_dst = os.path.join(dst_dir, filepart)
if os.path.islink(abs_src):
if not follow_symlinks and os.path.islink(abs_src):
files.append(d)
continue
# Remove these so they aren't visited by os.walk at all.
+2
View File
@@ -72,6 +72,8 @@ def check_symlinks():
if f.is_symlink():
if 'boost symlinks/boost/lib' in str(f):
continue
if 'follow symlinks/bar/dir2/dir3' in str(f):
continue
raise SystemExit(f'Test data dir contains symlink: {f}.')
@@ -0,0 +1 @@
../dir1
@@ -40,3 +40,15 @@ install_subdir(
strip_directory: true,
follow_symlinks: true,
)
install_subdir(
'bar',
install_dir: get_option('datadir') / 'subdir',
follow_symlinks: false,
)
install_subdir(
'bar',
install_dir: get_option('datadir') / 'subdir_followed',
follow_symlinks: true,
)
@@ -7,8 +7,12 @@
{"type": "link", "file": "usr/share/subdir/link1"},
{"type": "link", "file": "usr/share/subdir/link2.h"},
{"type": "file", "file": "usr/share/subdir/file1"},
{"type": "file", "file": "usr/share/subdir/bar/dir1/file1"},
{"type": "link", "file": "usr/share/subdir/bar/dir2/dir3"},
{"type": "file", "file": "usr/share/subdir_followed/link1"},
{"type": "file", "file": "usr/share/subdir_followed/link2.h"},
{"type": "file", "file": "usr/share/subdir_followed/file1"}
{"type": "file", "file": "usr/share/subdir_followed/file1"},
{"type": "file", "file": "usr/share/subdir_followed/bar/dir1/file1"},
{"type": "file", "file": "usr/share/subdir_followed/bar/dir2/dir3/file1"}
]
}