13 #ifndef __STOUT_INTERNAL_WINDOWS_REPARSEPOINT_HPP__ 14 #define __STOUT_INTERNAL_WINDOWS_REPARSEPOINT_HPP__ 92 WCHAR PathBuffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
93 } SymbolicLinkReparseBuffer;
118 return (attributes.
get() & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
126 const bool is_symLink = (data.
ReparseTag & IO_REPARSE_TAG_SYMLINK) != 0;
128 return Error(
"Data buffer is not a symlink");
132 const WCHAR* substitute_name =
135 const size_t substitute_name_length =
139 const WCHAR* print_name =
142 const size_t print_name_length =
146 std::wstring(substitute_name, substitute_name_length),
147 std::wstring(print_name, print_name_length),
163 bool resolved_path_is_directory = attributes.
get() & FILE_ATTRIBUTE_DIRECTORY;
189 const DWORD access_flags = resolved_path_is_directory
190 ? FILE_FLAG_BACKUP_SEMANTICS
191 : FILE_ATTRIBUTE_NORMAL;
193 const HANDLE handle = ::CreateFileW(
198 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
204 if (handle == INVALID_HANDLE_VALUE) {
223 bool resolved_path_is_directory = attributes.
get() & FILE_ATTRIBUTE_DIRECTORY;
247 const DWORD access_flags = resolved_path_is_directory
248 ? (FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS)
249 : FILE_FLAG_OPEN_REPARSE_POINT;
251 const HANDLE handle = ::CreateFileW(
256 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
262 if (handle == INVALID_HANDLE_VALUE) {
298 const BOOL reparse_data_obtained = ::DeviceIoControl(
300 FSCTL_GET_REPARSE_POINT,
308 if (!reparse_data_obtained) {
310 "'internal::windows::get_symbolic_link_data': 'DeviceIoControl' call " 322 const std::string& target,
323 const std::string& reparse_point)
329 bool target_is_folder =
false;
330 if (attributes.
isSome()) {
331 target_is_folder = attributes.
get() & FILE_ATTRIBUTE_DIRECTORY;
336 if (attribute_set.
isSome() && attribute_set.
get()) {
337 return Error(
"Path '" + target +
"' is already a reparse point");
340 DWORD
flags = target_is_folder ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
343 auto link = [&reparse_point, &target](
const DWORD
flags) {
344 return ::CreateSymbolicLinkW(
355 if (link(flags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
361 if (::GetLastError() == ERROR_INVALID_PARAMETER) {
373 #endif // __STOUT_INTERNAL_WINDOWS_REPARSEPOINT_HPP__ Try< SharedHandle > get_handle_no_follow(const std::string &absolute_path)
Definition: reparsepoint.hpp:215
Definition: nothing.hpp:16
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
Definition: windows.hpp:72
ULONG ReparseTag
Definition: reparsepoint.hpp:62
Try< DWORD > get_file_attributes(const std::wstring &path)
Definition: attributes.hpp:27
ULONG Flags
Definition: reparsepoint.hpp:83
Definition: error.hpp:108
USHORT SubstituteNameLength
Definition: reparsepoint.hpp:74
Definition: posix_signalhandler.hpp:23
USHORT PrintNameOffset
Definition: reparsepoint.hpp:77
USHORT Reserved
Definition: reparsepoint.hpp:66
FollowSymlink
Definition: reparsepoint.hpp:35
std::wstring print_name
Definition: reparsepoint.hpp:103
Try< bool > reparse_point_attribute_set(const std::wstring &absolute_path)
Definition: reparsepoint.hpp:111
Try< SymbolicLink > build_symbolic_link(const REPARSE_DATA_BUFFER &data)
Definition: reparsepoint.hpp:124
struct internal::windows::_REPARSE_DATA_BUFFER::@13 SymbolicLinkReparseBuffer
Try< SymbolicLink > get_symbolic_link_data(const HANDLE handle)
Definition: reparsepoint.hpp:271
WCHAR PathBuffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]
Definition: reparsepoint.hpp:92
constexpr Handle HANDLE
Definition: ingress.hpp:37
USHORT ReparseDataLength
Definition: reparsepoint.hpp:64
ULONG flags
Definition: reparsepoint.hpp:104
bool isSome() const
Definition: try.hpp:77
std::wstring substitute_name
Definition: reparsepoint.hpp:102
Try< hashmap< std::string, uint64_t > > stat(const std::string &hierarchy, const std::string &cgroup, const std::string &file)
static Try error(const E &e)
Definition: try.hpp:43
USHORT PrintNameLength
Definition: reparsepoint.hpp:79
USHORT SubstituteNameOffset
Definition: reparsepoint.hpp:72
Try< SharedHandle > get_handle_follow(const std::string &absolute_path)
Definition: reparsepoint.hpp:155
#define flags
Definition: decoder.hpp:18
Definition: attributes.hpp:24
bool isError() const
Definition: try.hpp:78
Definition: reparsepoint.hpp:100
struct internal::windows::_REPARSE_DATA_BUFFER REPARSE_DATA_BUFFER
std::wstring longpath(const std::string &path)
Definition: longpath.hpp:38
Definition: reparsepoint.hpp:58
Try< Nothing > create_symbolic_link(const std::string &target, const std::string &reparse_point)
Definition: reparsepoint.hpp:321