microsoft / microsoft/STL

<filesystem>: std::filesystem::exists fails when testing path naming unix socket

Open
#4,077 6 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.