Merge 1443c5a37eb062d75843eb91a2cfaf4d10ccdb55 into 2b4d7f239e0e749315fca1de7b2cf7438cf94a9a

This commit is contained in:
Hannah Green 2026-08-16 08:14:01 +02:00 committed by GitHub
commit 5e8aa36b0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -4085,7 +4085,9 @@ GHC_INLINE void copy_symlink(const path& existing_symlink, const path& new_symli
ec.clear();
auto to = read_symlink(existing_symlink, ec);
if (!ec) {
if (exists(to, ec) && is_directory(to, ec)) {
// Relative targets are relative to the source link parent (#211).
path lookup = to.is_absolute() ? to : (existing_symlink.parent_path() / to);
if (exists(lookup, ec) && is_directory(lookup, ec)) {
create_directory_symlink(to, new_symlink, ec);
}
else {

View File

@ -1918,6 +1918,18 @@ TEST_CASE("fs.op.copy_symlink - copy_symlink", "[filesystem][operations][fs.op.c
CHECK_NOTHROW(fs::copy_symlink("sdir", "sdirc2", ec));
CHECK(fs::exists("sdirc2"));
CHECK(!ec);
// Relative targets must be resolved against the source link parent
// (not cwd) when classifying directory vs file links on Windows.
fs::create_directories("nested/dir");
fs::create_directory_symlink("dir", "nested/slink");
CHECK_NOTHROW(fs::copy_symlink("nested/slink", "nested/slink_copy"));
CHECK(fs::read_symlink("nested/slink_copy") == "dir");
CHECK(fs::is_directory("nested/slink_copy"));
CHECK_NOTHROW(fs::copy_symlink("nested/slink", "nested/slink_copy2", ec));
CHECK(!ec);
CHECK(fs::read_symlink("nested/slink_copy2") == "dir");
CHECK(fs::is_directory("nested/slink_copy2"));
}
CHECK_THROWS_AS(fs::copy_symlink("bar", "barc"), fs::filesystem_error);
CHECK_NOTHROW(fs::copy_symlink("bar", "barc", ec));