`<filesystem>`: `std::filesystem::exists` returns false for path longer than 260 symbols

Abierto
#6,353 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
cpp

Línea de trabajo

Comienza compilando y ejecutando el reproductor de Windows/MSVC proporcionado para confirmar el comportamiento con una ruta de 262 caracteres. Después, localiza la implementación de std::filesystem::exists y su punto de entrada para el manejo de rutas de Windows; el trabajo estará terminado cuando una ruta existente de más de 260 caracteres devuelva true con un resultado de error-code claro y correcto.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug filesystem

Describe the bug

std::filesystem::exists returns false for an existing path longer than 260 characters and doesn't return an error (the error code is 0).

Command-line test case

C:\Temp>type repro.cpp
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <string>
#include <system_error>
#include <format>
#include <cassert>

int main()
{
    // File name longer than 260 characters
    const std::filesystem::path filePath = LR"(Reproduction_scenario_uniquie_folder\dddddddddddddddddddddddddddddd\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt)";

    std::wcout << std::format(L"filePath length: {}\n", filePath.wstring().size()); // 262

    // Create the folder path recursively if it is not already there.
    const auto mkdirResult = std::system(std::format("cmd.exe /c if not exist \"{}\" mkdir \"{}\"", filePath.parent_path().string(), filePath.parent_path().string()).c_str());
    assert(mkdirResult == 0);

    // Create the file
    const auto echoResult = std::system(std::format("cmd.exe /c echo AAAA> \"{}\"", filePath.string()).c_str());
    assert(echoResult == 0);

    // Check if the file exists
    std::error_code errorCode;
    bool exists = std::filesystem::exists(filePath, errorCode);

    std::cout << std::format("exists: {}\n", exists);
    std::cout << std::format("errorCode value: {}\n", errorCode.value());
    std::cout << std::format("errorCode category: {}\n", errorCode.category().name());
    std::cout << std::format("errorCode message: {}\n", errorCode.message());

    return 1;
}

C:\Temp>cl /EHsc /W4 /std:c++latest .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36248 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

repro.cpp
Microsoft (R) Incremental Linker Version 14.51.36248.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

C:\Temp>.\repro.exe
filePath length: 262
exists: false
errorCode value: 0
errorCode category: system
errorCode message: The operation completed successfully.

Expected behavior

std::filesystem::exists should return true if the file with a path longer than 260 characters exists.

Lenguaje dominante
C++
Estrellas
11.2k
Forks
1.7k
Merge medio
4 d 4 h
PR fusionados (30 d)
14

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/STL

Todos los issues de microsoft/STL

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.