6#if defined(MAYAFLUX_PLATFORM_WINDOWS)
7#ifndef WIN32_LEAN_AND_MEAN
8#define WIN32_LEAN_AND_MEAN
24 std::filesystem::path
path;
44 std::filesystem::path
path;
50#if defined(MAYAFLUX_PLATFORM_MACOS)
66 std::vector<std::filesystem::path> directories;
68 const auto add_variable = [&directories](
const char* name) {
73 std::filesystem::path directory(value);
74 if (directory.is_absolute()) {
75 directories.push_back(std::move(directory));
79#if defined(MAYAFLUX_PLATFORM_WINDOWS)
82#elif defined(MAYAFLUX_PLATFORM_MACOS)
83 add_variable(
"TMPDIR");
85 add_variable(
"XDG_RUNTIME_DIR");
86 directories.emplace_back(
"/run/user/" + std::to_string(::geteuid()));
96#if defined(MAYAFLUX_PLATFORM_WINDOWS)
101 const auto status = std::filesystem::status(directory, ec);
105 const auto permissions = status.permissions();
106 const bool others_write = (permissions & std::filesystem::perms::others_write) != std::filesystem::perms::none;
107 const bool sticky = (permissions & std::filesystem::perms::sticky_bit) != std::filesystem::perms::none;
108 return !others_write || sticky;
112 inline bool entry_is_socket(
const std::filesystem::file_status& status,
const std::filesystem::path& path)
114#if defined(MAYAFLUX_PLATFORM_WINDOWS)
115 if (status.type() == std::filesystem::file_type::socket) {
118 constexpr DWORD af_unix_reparse_tag = 0x80000023;
119 WIN32_FIND_DATAW found {};
120 const HANDLE handle = FindFirstFileW(path.c_str(), &found);
121 if (handle == INVALID_HANDLE_VALUE) {
125 return (found.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0
126 && found.dwReserved0 == af_unix_reparse_tag;
129 return status.type() == std::filesystem::file_type::socket;
144 return std::unexpected(*failure);
146 std::vector<std::filesystem::path> tried;
148 tried.push_back(directory);
150 return directory / from.file_name;
169 const auto entry = std::filesystem::symlink_status(path, ec);
183 std::vector<std::filesystem::path> sockets;
187 std::filesystem::directory_iterator entry(directory, ec);
188 const std::filesystem::directory_iterator end;
190 while (!ec && entry != end) {
192 sockets.push_back(entry->path());
198 std::ranges::sort(sockets);
199 const auto duplicates = std::ranges::unique(sockets);
200 sockets.erase(duplicates.begin(), duplicates.end());
227template <std::predicate<const std::filesystem::path&> Probe>
232 return std::unexpected(resolved.error());
234 const std::filesystem::path path = std::move(*resolved);
240 const std::filesystem::path directory = path.parent_path();
252 const auto entry = std::filesystem::symlink_status(path, ec);
253 if (entry.type() == std::filesystem::file_type::not_found) {
254 return UnixSocket { .path = path, .replaced_stale =
false };
263 if (is_alive(path)) {
267 std::filesystem::remove(path, ec);
271 return UnixSocket { .path = path, .replaced_stale =
true };
283#if defined(MAYAFLUX_PLATFORM_WINDOWS)
288 std::filesystem::permissions(path,
289 std::filesystem::perms::owner_read | std::filesystem::perms::owner_write,
290 std::filesystem::perm_options::replace, ec);