]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/filesystem/test/issues/99_canonical_with_junction_point.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / filesystem / test / issues / 99_canonical_with_junction_point.cpp
CommitLineData
20effc67
TL
1// Boost operations_test.cpp ---------------------------------------------------------//
2
3// Copyright Alexander Grund 2020
4
5// Distributed under the Boost Software License, Version 1.0.
6// See http://www.boost.org/LICENSE_1_0.txt
7
8// Library home page: http://www.boost.org/libs/filesystem
9
10#include <iostream>
11
12#if defined(BOOST_FILESYSTEM_HAS_MKLINK)
13
14#include <boost/filesystem.hpp>
15#include <boost/system/error_code.hpp>
16#include <boost/core/lightweight_test.hpp>
17#include <cstdlib>
18#include <vector>
19
20namespace fs = boost::filesystem;
21
22struct TmpDir
23{
1e59de90
TL
24 fs::path path;
25 TmpDir(const fs::path& base) :
26 path(fs::absolute(base) / fs::unique_path())
27 {
28 fs::create_directories(path);
29 }
30 ~TmpDir()
31 {
32 boost::system::error_code ec;
33 fs::remove_all(path, ec);
34 }
20effc67
TL
35};
36
37// Test fs::canonical for various path in a Windows directory junction point
38// This failed before due to broken handling of absolute paths and ignored ReparseTag
39int main()
40{
41
1e59de90
TL
42 const fs::path cwd = fs::current_path();
43 const TmpDir tmp(cwd);
44 const fs::path junction = tmp.path / "junction";
45 const fs::path real = tmp.path / "real";
46 const fs::path subDir = "sub";
47 fs::create_directories(real / subDir);
48 fs::current_path(tmp.path);
49 BOOST_TEST(std::system("mklink /J junction real") == 0);
50 BOOST_TEST(fs::exists(junction));
51
52 // Due to a bug there was a dependency on the current path so try the below for all:
53 std::vector< fs::path > paths;
54 paths.push_back(cwd);
55 paths.push_back(junction);
56 paths.push_back(real);
57 paths.push_back(junction / subDir);
58 paths.push_back(real / subDir);
59 for (std::vector< fs::path >::iterator it = paths.begin(); it != paths.end(); ++it)
60 {
61 std::cout << "Testing in " << *it << std::endl;
62 fs::current_path(*it);
63
64 // Used by canonical, must work too
65 BOOST_TEST(fs::read_symlink(junction) == real);
66
67 BOOST_TEST(fs::canonical(junction) == real);
68 BOOST_TEST(fs::canonical(junction / subDir) == real / subDir);
69 }
70
71 // Restore the original current directory so that temp directory can be removed
72 fs::current_path(cwd);
73
74 return boost::report_errors();
20effc67
TL
75}
76
77#else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
78
79int main()
80{
1e59de90
TL
81 std::cout << "Skipping test as the target system does not support mklink." << std::endl;
82 return 0;
20effc67
TL
83}
84
85#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)