]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/test/windows_attributes.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / filesystem / test / windows_attributes.cpp
1 // windows_attributes ----------------------------------------------------------------//
2
3 // Copyright Beman Dawes 2010
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 //--------------------------------------------------------------------------------------//
11
12 // Useful for debugging status related issues //
13
14 //--------------------------------------------------------------------------------------//
15
16 #include <boost/filesystem.hpp>
17 #include <boost/detail/lightweight_main.hpp>
18 #include <windows.h>
19 #include <map>
20 #include <utility>
21 #include <iostream>
22 #include <string>
23
24 using std::make_pair;
25 namespace fs = boost::filesystem;
26
27 int cpp_main(int argc, char* argv[])
28 {
29 typedef std::map< DWORD, std::string > decode_type;
30 decode_type table;
31
32 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE"));
33 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED"));
34 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE"));
35 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY"));
36 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED"));
37 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN"));
38 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"));
39 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE"));
40 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY"));
41 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT"));
42 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE"));
43 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM"));
44 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY"));
45 table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
46
47 if (argc < 2)
48 {
49 std::cout << "Usage: windows_attributes path\n";
50 return 1;
51 }
52
53 // report Win32 ::GetFileAttributesA()
54
55 DWORD at(::GetFileAttributesA(argv[1]));
56 if (at == INVALID_FILE_ATTRIBUTES)
57 {
58 std::cout << "GetFileAttributes(\"" << argv[1]
59 << "\") returned INVALID_FILE_ATTRIBUTES\n";
60 return 0;
61 }
62
63 std::cout << "GetFileAttributes(\"" << argv[1]
64 << "\") returned ";
65
66 bool bar = false;
67 for (decode_type::iterator it = table.begin(); it != table.end(); ++it)
68 {
69 if (!(it->first & at))
70 continue;
71 if (bar)
72 std::cout << " | ";
73 bar = true;
74 std::cout << it->second;
75 at &= ~it->first;
76 }
77 std::cout << std::endl;
78
79 if (at)
80 std::cout << "plus unknown attributes " << at << std::endl;
81
82 // report Boost Filesystem file_type
83
84 fs::file_status stat = fs::status(argv[1]);
85
86 const char* types[] =
87 {
88 "status_error",
89 "file_not_found",
90 "regular_file",
91 "directory_file",
92 // the following may not apply to some operating systems or file systems
93 "symlink_file",
94 "block_file",
95 "character_file",
96 "fifo_file",
97 "socket_file",
98 "reparse_file", // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
99 "type_unknown" // file does exist", but isn't one of the above types or
100 // we don't have strong enough permission to find its type
101 };
102
103 std::cout << "boost::filesystem::status().type() is " << types[stat.type()] << std::endl;
104
105 return 0;
106 }