13 #ifndef __STOUT_INTERNAL_WINDOWS_REPARSEPOINT_HPP__
14 #define __STOUT_INTERNAL_WINDOWS_REPARSEPOINT_HPP__
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;
188 const DWORD access_flags = resolved_path_is_directory
189 ? FILE_FLAG_BACKUP_SEMANTICS
190 : FILE_ATTRIBUTE_NORMAL;
192 const HANDLE handle = ::CreateFileW(
201 if (handle == INVALID_HANDLE_VALUE) {
220 bool resolved_path_is_directory = attributes.
get() & FILE_ATTRIBUTE_DIRECTORY;
243 const DWORD access_flags = resolved_path_is_directory
244 ? (FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS)
245 : FILE_FLAG_OPEN_REPARSE_POINT;
247 const HANDLE handle = ::CreateFileW(
256 if (handle == INVALID_HANDLE_VALUE) {
292 const BOOL reparse_data_obtained = ::DeviceIoControl(
294 FSCTL_GET_REPARSE_POINT,
302 if (!reparse_data_obtained) {
304 "'internal::windows::get_symbolic_link_data': 'DeviceIoControl' call "
316 const std::string& target,
317 const std::string& reparse_point)
323 bool target_is_folder =
false;
324 if (attributes.
isSome()) {
325 target_is_folder = attributes.
get() & FILE_ATTRIBUTE_DIRECTORY;
330 if (attribute_set.
isSome() && attribute_set.
get()) {
331 return Error(
"Path '" + target +
"' is already a reparse point");
334 DWORD
flags = target_is_folder ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
337 auto link = [&reparse_point, &target](
const DWORD
flags) {
338 return ::CreateSymbolicLinkW(
349 if (link(flags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)) {
355 if (::GetLastError() == ERROR_INVALID_PARAMETER) {
367 #endif // __STOUT_INTERNAL_WINDOWS_REPARSEPOINT_HPP__
Try< SharedHandle > get_handle_no_follow(const std::string &absolute_path)
Definition: reparsepoint.hpp:212
Definition: nothing.hpp:16
Definition: errorbase.hpp:35
Definition: windows.hpp:78
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:106
USHORT SubstituteNameLength
Definition: reparsepoint.hpp:74
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:265
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:70
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:42
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
bool isError() const
Definition: try.hpp:71
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:315
const T & get() const
Definition: try.hpp:73