Skip to content

file: support directory listing on Windows - #22577

Closed
hunterinvariants wants to merge 1 commit into
curl:masterfrom
hunterinvariants:file-win32-directory-listing
Closed

hunterinvariants wants to merge 1 commit into
curl:masterfrom
hunterinvariants:file-win32-directory-listing

Conversation

@hunterinvariants

Copy link
Copy Markdown
Contributor

Implement file:// directory listings on desktop Windows using FindFirstFile.

The new internal curlx wrapper keeps the existing Unicode and extended-path handling. Directory entries are returned as UTF-8 and dot-prefixed entries remain excluded, matching the existing implementation on other platforms.

Test 3203 is enabled on Windows and covers a non-ASCII filename in Unicode builds.

Verified with MinGW x64 Unicode, x64 ANSI and x86 ANSI builds; manual directory matrices on Windows 11 and Windows Server 2025; a long Unicode path on Windows 11; and the Linux non-flaky suite (1602 tests).

Addresses #6379.

@github-actions github-actions Bot added the tests label Aug 13, 2026
@hunterinvariants

Copy link
Copy Markdown
Contributor Author

One Windows job was cancelled at its 15-minute job timeout while the test suite was running. Configure, build and build-tests completed successfully, and test 3203 passes in the other Windows jobs. I cannot rerun the upstream workflow; could someone rerun the cancelled job?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds desktop Windows support for file:// directory listings while preserving Unicode and long-path handling.

Changes:

  • Detects directories when Windows file opening fails.
  • Enumerates entries with FindFirstFile.
  • Enables Windows testing, including Unicode filenames.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
lib/file.c Implements Windows directory detection and listing.
lib/curlx/fopen.c Adds a UTF-8-aware FindFirstFile wrapper.
lib/curlx/fopen.h Declares the new wrapper.
tests/data/test3203 Enables Windows and Unicode directory-listing coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/file.c Outdated
@hunterinvariants
hunterinvariants force-pushed the file-win32-directory-listing branch from 0497e90 to 60aa66a Compare August 13, 2026 20:56
@hunterinvariants

hunterinvariants commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

The remaining MSVC job failed before running tests because the certificate generator could not find a working openssl executable:

Missing or broken 'openssl' tool. openssl 1.0.2+ is required.\n

The same job reached the test suite in the previous run, and all other 212 checks passed. This appears to be a runner/tooling issue. I cannot rerun the upstream workflow; could someone rerun the failed job?

@dfandrich

dfandrich commented Aug 13, 2026 via email

Copy link
Copy Markdown
Contributor

@hunterinvariants

Copy link
Copy Markdown
Contributor Author

Builds with opendir() already have directory listing support. Native MSVC builds do not: they fall through to “Directory listing not yet implemented” and return error 37. This PR adds the Win32 implementation for those builds, while also using the Unicode/long-path conversion used by the existing curlx file wrappers.

@bagder

bagder commented Aug 14, 2026

Copy link
Copy Markdown
Member

Was this previous limitation documented anywhere that needs an update too now?

Comment thread lib/file.c Outdated
if(result) {
size_t pathlen = strlen(path);

/* Some Windows CRT variants reject trailing directory separators. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know more about which variants? Can we maybe include details?
E.g., is UCRT affected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reproduced failures are the x86 and x64 MinGW-w64 ANSI builds, both linked to msvcrt.dll. The Unicode build is also linked to msvcrt.dll, but uses the wide-character path and passes. So the evidence is specific to narrow stat() with MSVCRT. I have not tested UCRT and updated the comment to avoid implying that it is affected.

@vszakats

vszakats commented Aug 14, 2026

Copy link
Copy Markdown
Member

The remaining MSVC job failed before running tests because the certificate generator could not find a working openssl executable:

Missing or broken 'openssl' tool. openssl 1.0.2+ is required.

Can't remember seeing this one before. Seems safe to ignore unless it's reoccuring.

edit: another one: https://github.com/curl/curl/actions/runs/31784619882/job/94717691027
edit 2: can be related to windows-2025-vs2026 Version: 20260810.198.2 (vs: 20260803.193.1 working OK)

Comment thread lib/file.c Outdated
}

#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
static CURLcode file_win32_list(struct Curl_easy *data, const char *path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static CURLcode file_win32_list(struct Curl_easy *data, const char *path)
static CURLcode win32_file_list(struct Curl_easy *data, const char *path)

minor name suggestion to keep win32 in the front to match rest of code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed as suggested.

@hunterinvariants

Copy link
Copy Markdown
Contributor Author

Yes. docs/TODO.md still had a FILE item saying directory listings require opendir() and suggesting Windows support. I removed that completed item in the latest revision.

@hunterinvariants
hunterinvariants force-pushed the file-win32-directory-listing branch from 47e8182 to 5d2f2e6 Compare August 14, 2026 12:02
vszakats added a commit that referenced this pull request Aug 14, 2026
In GitHub runner image windows-2025-vs2026 v20260810.198.2, the default
Perl binary changed from MSYS2 to Strawberry. The reason is that the MSYS2
installation not longer has Perl preinstalled.

As seen in CMake configuration:
```diff
- -- Found Perl: C:/a/_temp/msys64/usr/bin/perl.exe (found version "5.42.2")
+ -- Found Perl: C:/Strawberry/perl/bin/perl.exe (found version "5.42.0")
```

curl's Perl scripts require an MSYS2 Perl. Fix by installing it manually
in this one job.

Symptom was `gencert.pl` no longer finding openssl.exe:
```
Missing or broken 'openssl' tool. openssl 1.0.2+ is required.
```
Then the script hanging while trying to trace it.

Also:
- add distinct error message and list PATH elements if openssl is not
  found via `gencert.pl`.
- tried falling back to Git for Windows Perl, which caused the test step
  to either hang or run too slowly to fit the time slot.

Refs:
actions/runner-images#14541
https://github.com/actions/runner-images/releases/tag/win25-vs2026%2F20260810.198

Bug: #22577 (comment)
Bug: #22577 (comment)

Closes #22580
@vszakats

vszakats commented Aug 14, 2026

Copy link
Copy Markdown
Member

Rebasing on master will fix the MSVC job. It turned out to be a real, non-flaky fallout due to a breaking GH runner image update. Ref: #22580

@bagder bagder closed this in c7c42af Aug 15, 2026
@bagder

bagder commented Aug 15, 2026

Copy link
Copy Markdown
Member

Thanks!

@hunterinvariants
hunterinvariants deleted the file-win32-directory-listing branch August 15, 2026 13:33
vszakats added a commit that referenced this pull request Aug 16, 2026
`opendir()` was used previously with mingw-w64 for `file://` directory
listing support. This was replaced by a native Win32 solution on all
Windows platforms, leaving `opendir()` no longer used. Drop related
feature detections.

Follow-up to c7c42af #22577

Closes #22588
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

5 participants