]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/test/issues/99_canonical_with_junction_point.cpp
1 // Boost operations_test.cpp ---------------------------------------------------------//
3 // Copyright Alexander Grund 2020
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // Library home page: http://www.boost.org/libs/filesystem
12 #if defined(BOOST_FILESYSTEM_HAS_MKLINK)
14 #include <boost/filesystem.hpp>
15 #include <boost/system/error_code.hpp>
16 #include <boost/core/lightweight_test.hpp>
20 namespace fs
= boost::filesystem
;
25 TmpDir(const fs::path
& base
): path(fs::absolute(base
) / fs::unique_path())
27 fs::create_directories(path
);
31 boost::system::error_code ec
;
32 fs::remove_all(path
, ec
);
36 // Test fs::canonical for various path in a Windows directory junction point
37 // This failed before due to broken handling of absolute paths and ignored ReparseTag
41 const fs::path cwd
= fs::current_path();
42 const TmpDir
tmp(cwd
);
43 const fs::path junction
= tmp
.path
/ "junction";
44 const fs::path real
= tmp
.path
/ "real";
45 const fs::path subDir
= "sub";
46 fs::create_directories(real
/ subDir
);
47 fs::current_path(tmp
.path
);
48 BOOST_TEST(std::system("mklink /j junction real") == 0);
49 BOOST_TEST(fs::exists(junction
));
51 // Due to a bug there was a dependency on the current path so try the below for all:
52 std::vector
<fs::path
> paths
;
54 paths
.push_back(junction
);
55 paths
.push_back(real
);
56 paths
.push_back(junction
/ subDir
);
57 paths
.push_back(real
/ subDir
);
58 for (std::vector
<fs::path
>::iterator it
= paths
.begin(); it
!= paths
.end(); ++it
)
60 std::cout
<< "Testing in " << *it
<< std::endl
;
61 fs::current_path(*it
);
63 // Used by canonical, must work too
64 BOOST_TEST(fs::read_symlink(junction
) == real
);
66 BOOST_TEST(fs::canonical(junction
) == real
);
67 BOOST_TEST(fs::canonical(junction
/ subDir
) == real
/ subDir
);
70 // Restore the original current directory so that temp directory can be removed
71 fs::current_path(cwd
);
73 return boost::report_errors();
76 #else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
80 std::cout
<< "Skipping test as the target system does not support mklink." << std::endl
;
84 #endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)