From ae4c3e16999b9f5ae1932df7df188cd8b1e970fb Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sun, 16 Oct 2016 00:29:22 +0000 Subject: [PATCH] Implement LWG 2681 and 2682 llvm-svn: 284316 --- .../experimental/filesystem/operations.cpp | 3 ++ .../fs.op.funcs/fs.op.copy/copy.pass.cpp | 41 +++++++++++++++++++ libcxx/www/upcoming_meeting.html | 8 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp index eba7ae368e26..4c60a17e976b 100644 --- a/libcxx/src/experimental/filesystem/operations.cpp +++ b/libcxx/src/experimental/filesystem/operations.cpp @@ -236,6 +236,9 @@ void __copy(const path& from, const path& to, copy_options options, } return; } + else if (is_directory(f) && bool(copy_options::create_symlinks & options)) { + return set_or_throw(make_error_code(errc::is_a_directory), ec, "copy"); + } else if (is_directory(f) && (bool(copy_options::recursive & options) || copy_options::none == options)) { diff --git a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp index 61d963a510d8..6e10ce51ce3a 100644 --- a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp @@ -257,6 +257,47 @@ TEST_CASE(from_is_directory) } } +TEST_CASE(test_copy_symlinks_to_symlink_dir) +{ + scoped_test_env env; + const path file1 = env.create_file("file1", 42); + const path file2 = env.create_file("file2", 101); + const path file2_sym = env.create_symlink(file2, "file2_sym"); + const path dir = env.create_dir("dir"); + const path dir_sym = env.create_symlink(dir, "dir_sym"); + { + std::error_code ec = GetTestEC(); + fs::copy(file1, dir_sym, copy_options::copy_symlinks, ec); + TEST_CHECK(!ec); + const path dest = env.make_env_path("dir/file1"); + TEST_CHECK(exists(dest)); + TEST_CHECK(!is_symlink(dest)); + TEST_CHECK(file_size(dest) == 42); + } +} + + +TEST_CASE(test_dir_create_symlink) +{ + scoped_test_env env; + const path dir = env.create_dir("dir1"); + const path dest = env.make_env_path("dne"); + { + std::error_code ec = GetTestEC(); + fs::copy(dir, dest, copy_options::create_symlinks, ec); + TEST_CHECK(ec == std::make_error_code(std::errc::is_a_directory)); + TEST_CHECK(!exists(dest)); + TEST_CHECK(!is_symlink(dest)); + } + { + std::error_code ec = GetTestEC(); + fs::copy(dir, dest, copy_options::create_symlinks|copy_options::recursive, ec); + TEST_CHECK(ec == std::make_error_code(std::errc::is_a_directory)); + TEST_CHECK(!exists(dest)); + TEST_CHECK(!is_symlink(dest)); + } +} + TEST_CASE(test_otherwise_no_effects_clause) { scoped_test_env env; diff --git a/libcxx/www/upcoming_meeting.html b/libcxx/www/upcoming_meeting.html index 6c8b29e92617..cb781a432fd7 100644 --- a/libcxx/www/upcoming_meeting.html +++ b/libcxx/www/upcoming_meeting.html @@ -94,8 +94,8 @@ 2678std::filesystem enum classes overspecifiedIssaquahNothing to do 2679Inconsistent Use of Effects and Equivalent ToIssaquahNothing to do 2680Add "Equivalent to" to filesystemIssaquahNothing to do - 2681filesystem::copy() cannot copy symlinksIssaquah - 2682filesystem::copy() won't create a symlink to a directoryIssaquah + 2681filesystem::copy() cannot copy symlinksIssaquahWe already do this + 2682filesystem::copy() won't create a symlink to a directoryIssaquahImplemented in trunk 2686Why is std::hash specialized for error_code, but not error_condition?IssaquahPatch ready 2694Application of LWG 436 accidentally deleted definition of "facet"IssaquahNothing to do 2696Interaction between make_shared and enable_shared_from_this is underspecifiedIssaquah @@ -172,8 +172,8 @@
  • 2678 - File System; Eric?
  • 2679 - This is just wording cleanup.
  • 2680 - This is just wording cleanup.
  • -
  • 2681 - File System; Eric?
  • -
  • 2682 - File System; Eric?
  • +
  • 2681 - LGTM
  • +
  • 2682 - Current PR is incorrect. A modified version has been implemented
  • 2686 - Patch and tests ready
  • 2694 - Restoring inadvertently deleted text. No code changes needed.
  • 2696 - I suspect that this is just better specification of the existing structure. Probably need more tests for this.