From: Gerd von Egidy Date: Wed, 16 Dec 2015 15:37:55 +0000 (+0100) Subject: test handling of symlinks to directories in recursive_delete: seems to be buggy X-Git-Tag: v2.8~12 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=a50de522ccdda3888a39d5e728ce9ace85be7938;p=libi2ncommon test handling of symlinks to directories in recursive_delete: seems to be buggy --- diff --git a/test/test_filefunc.cpp b/test/test_filefunc.cpp index 3335241..0a8426a 100644 --- a/test/test_filefunc.cpp +++ b/test/test_filefunc.cpp @@ -428,6 +428,68 @@ BOOST_AUTO_TEST_CASE(TestRecursiveDeleteKeepParentDir) BOOST_CHECK_EQUAL(true, I2n::rmdir(unique_dir)); } +BOOST_AUTO_TEST_CASE(TestRecursiveDeleteSymlinkedDirs1) +{ + // Create unique directory + string unique_dir = I2n::mkdtemp("foobar.XXXXXX"); + BOOST_REQUIRE(unique_dir.size() > 0); + + // Test if it's really a directory + BOOST_CHECK_EQUAL(true, Stat(unique_dir).is_directory()); + + // Create dirs and files below it + const std::string sub_dir = unique_dir + "/" + "some_subdir"; + const std::string some_file = sub_dir + "/" + "some_file"; + const std::string dir_symlink_within_unique_dir = unique_dir + "/" + "dir_symlink_within_unique_dir"; + BOOST_CHECK_EQUAL(true, I2n::mkdir(sub_dir)); + BOOST_CHECK_EQUAL(true, write_file(some_file, "foobar")); + BOOST_CHECK_EQUAL(true, symlink(sub_dir, dir_symlink_within_unique_dir)); + + // Unlink it + BOOST_CHECK_EQUAL(true, I2n::recursive_delete(unique_dir)); + BOOST_CHECK_EQUAL(false, Stat(unique_dir).is_directory()); +} + +BOOST_AUTO_TEST_CASE(TestRecursiveDeleteSymlinkedDirs2) +{ + // Create unique directory + string unique_dir = I2n::mkdtemp("foobar.XXXXXX"); + BOOST_REQUIRE(unique_dir.size() > 0); + + // Test if it's really a directory + BOOST_CHECK_EQUAL(true, Stat(unique_dir).is_directory()); + + // Create another unique directory + string other_unique_dir = I2n::mkdtemp("foobar_other.XXXXXX"); + BOOST_REQUIRE(other_unique_dir.size() > 0); + + // Test if it's really a directory + BOOST_CHECK_EQUAL(true, Stat(other_unique_dir).is_directory()); + + const std::string other_file = other_unique_dir + "/" + "other_file"; + BOOST_CHECK_EQUAL(true, write_file(other_file, "foobar")); + + // Create dirs and files below it + const std::string sub_dir = unique_dir + "/" + "some_subdir"; + const std::string some_file = sub_dir + "/" + "some_file"; + const std::string dir_symlink_to_outside_unique_dir = unique_dir + "/" + "dir_symlink_to_outside_unique_dir"; + BOOST_CHECK_EQUAL(true, I2n::mkdir(sub_dir)); + BOOST_CHECK_EQUAL(true, write_file(some_file, "foobar")); + BOOST_CHECK_EQUAL(true, symlink(other_unique_dir, dir_symlink_to_outside_unique_dir)); + + // Unlink it + BOOST_CHECK_EQUAL(true, I2n::recursive_delete(unique_dir)); + BOOST_CHECK_EQUAL(false, Stat(unique_dir).is_directory()); + + // other unique dir must still be there + BOOST_CHECK_EQUAL(true, Stat(other_unique_dir).is_directory()); + BOOST_CHECK_EQUAL(true, Stat(other_file).is_regular_file()); + + // finally delete the other unique dir + BOOST_CHECK_EQUAL(true, I2n::recursive_delete(other_unique_dir)); + BOOST_CHECK_EQUAL(false, Stat(other_unique_dir).is_directory()); +} + BOOST_AUTO_TEST_CASE(TestMkdtempBrokenTemplate) { // Broken directory template -> fail