<filesystem>: std::filesystem::exists fails when testing path naming unix socket
Open
Nobody has claimed this yet.
bug
filesystem
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Description
std::filesystem::exists(p), where p is a path pointing to a unix socket (e.g. p = "./test.sock"), throws an exception with the message exists: unknown error: "./test.sock".
Command-line test case
C:\temp> cat test.cpp
#include <exception>
#include <filesystem>
#include <iostream>
#include <cassert>
#ifndef _WINSOCKAPI_
# define _WINSOCKAPI_
#endif
#include <WinSock2.h>
#include <ws2ipdef.h>
#include <afunix.h>
#pragma comment(lib, "ws2_32.lib")
int main()
{
WSADATA wsa_data;
assert(WSAStartup(MAKEWORD(2, 2), &wsa_data) == 0);
auto socket = WSASocketW(AF_UNIX, SOCK_STREAM, 0, 0, 0, 0);
assert(socket != SOCKET_ERROR);
sockaddr_un addr;
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, "./test.sock", sizeof(addr.sun_path));
assert(bind(socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) != SOCKET_ERROR);
assert(listen(socket, 1) != SOCKET_ERROR);
try
{
(void)std::filesystem::exists("./test.sock");
}
catch (std::exception const& e)
{
std::cout << e.what() << std::endl;
}
}
C:\temp> cl /std:c++17 /EHsc /Gr test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32822 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
Microsoft (R) Incremental Linker Version 14.37.32822.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
C:\temp> ./test.exe
exists: unknown error: "./test.sock"
Expected behavior
I expect the call to std::filesystem::exists to return true.
STL version
Microsoft Visual Studio Community 2022
Version 17.8.0 Preview 1.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied test.cpp reproducer and the std::filesystem::exists entry point; trace its Windows handling of a bound AF_UNIX socket. Done when the reproducer returns true without throwing for ./test.sock.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100