Skip to content

chunkio: replace Windows API PathIsDirectoryA for nano server compatibility #10734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zanejohnson-azure
Copy link

@zanejohnson-azure zanejohnson-azure commented Aug 14, 2025

Replace Windows API calls in chunkio dirent.c with Nano Server compatible alternatives. The original APIs are not available in Windows Nano Server, preventing Fluent Bit from running in minimal Windows environments and containers.

This change maintains full functionality while ensuring compatibility across all Windows variants including Nano Server deployments.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when opening directories on Windows by hardening path validation, reducing false positives/negatives for non-directory paths and preventing unexpected failures.
    • Edge cases such as missing paths or invalid attributes now return errors more consistently.
    • Reduced reliance on optional Windows components, improving portability across different installations.
    • No changes to public APIs; behavior for valid directories remains unchanged.

…bility

Replace Windows API call PathIsDirectoryA that is not available on Windows Nano
Server with compatible alternatives.

The changes maintain full functionality while using APIs that are available
across all Windows variants including Nano Server.

Signed-off-by: zanejohnson-azure <zanejohnson@microsoft.com>
Copy link

coderabbitai bot commented Aug 14, 2025

Walkthrough

The Windows-specific dirent implementation updates opendir to use GetFileAttributesA for directory detection instead of PathIsDirectoryA, removing the shlwapi dependency. It adds a local DWORD for attributes and returns NULL when attributes are invalid or the directory flag is absent. No public APIs changed.

Changes

Cohort / File(s) Summary
Win32 dirent directory check
lib/chunkio/src/win32/dirent.c
Replace PathIsDirectoryA with GetFileAttributesA for directory checks in opendir; add attrs guard for INVALID_FILE_ATTRIBUTES and missing FILE_ATTRIBUTE_DIRECTORY; remove reliance on shlwapi.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

I twitch my ears at attributes’ might,
No shlwapi in moonlit night.
A DWORD gleams—flags align,
Directories found by simple sign.
I hop through paths, neat and spry—
GetFileAttributesA, oh my!
Carrots compiled; builds fly by. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
lib/chunkio/src/win32/dirent.c (2)

33-33: Fix ANSI/Wide API mismatch to avoid build/runtime issues

The file mixes A-suffixed APIs with generic types/functions:

  • WIN32_FIND_DATA (generic) is paired with FindFirstFileA.
  • FindNextFile (generic) is used in readdir, while FindFirstFileA is used in opendir.

If UNICODE is defined, these mismatches will break compilation or lead to type inconsistencies. Use A-suffixed types/APIs consistently.

Apply this diff:

-    WIN32_FIND_DATA find_data;
+    WIN32_FIND_DATAA find_data;
-        if (FindNextFile(d->h, &d->find_data) == 0) {
+        if (FindNextFileA(d->h, &d->find_data) == 0) {

Also applies to: 115-116


58-75: Prevent out-of-bounds read on empty path and accept both slash types

create_pattern reads path[len - 1] without guarding len > 0, which dereferences before the buffer for empty strings. Also, Windows accepts both '' and '/' as separators.

Apply this diff:

-    size_t len = strlen(path);
+    size_t len = strlen(path);
     size_t buflen = len + 3;
 
     buf = malloc(buflen);
     if (buf == NULL) {
         return NULL;
     }
 
     strcpy_s(buf, buflen, path);
 
-    if (path[len - 1] == '\\') {
+    if (len == 0) {
+        /* Empty path is invalid for opendir semantics */
+        free(buf);
+        return NULL;
+    }
+
+    /* Accept both backslash and forward slash */
+    if (path[len - 1] == '\\' || path[len - 1] == '/') {
         strcat_s(buf, buflen, "*");
     }
     else {
         strcat_s(buf, buflen, "\\*");
     }
     return buf;
🧹 Nitpick comments (4)
lib/chunkio/src/win32/dirent.c (4)

40-50: Use DWORD for file attribute parameter type

get_filetype takes an int but receives Win32 file attributes (DWORD). Use DWORD to avoid implicit narrowing and better reflect API types.

Apply this diff:

-static unsigned char get_filetype(int dwFileAttributes)
+static unsigned char get_filetype(DWORD dwFileAttributes)
 {
     if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
         return DT_DIR;
     }
     else if (dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
         return DT_LNK;
     }
 
     return DT_REG;
 }

No call-site changes are needed since d->find_data.dwFileAttributes is already a DWORD.

Also applies to: 122-123


25-27: Include standard headers explicitly

malloc/calloc/free/strlen/strcpy_s/strcat_s are used but <stdlib.h> and <string.h> are not included here. Include them to ensure prototypes and avoid implicit declarations across compilers.

Apply this diff:

 #include <Windows.h>
 
 #include "dirent.h"
+#include <stdlib.h>
+#include <string.h>

21-23: Typo in comment (“FIndFirstFile”)

Minor spelling fix.

Apply this diff:

- * Win32's FIndFirstFile/FindNextFile API.
+ * Win32's FindFirstFile/FindNextFile API.

38-40: Typo in comment (“flle” -> “file”)

Minor spelling fix.

Apply this diff:

- * Guess POSIX flle type from Win32 file attributes.
+ * Guess POSIX file type from Win32 file attributes.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fb0b394 and 8cc6767.

📒 Files selected for processing (1)
  • lib/chunkio/src/win32/dirent.c (1 hunks)
🔇 Additional comments (1)
lib/chunkio/src/win32/dirent.c (1)

81-83: Nano Server–compatible directory check: LGTM

Switching to GetFileAttributesA removes the shlwapi dependency and aligns with Nano Server constraints while preserving behavior. Good change.

@edsiper
Copy link
Member

edsiper commented Aug 14, 2025

would you please submit this PR to fluent/chunkio repo ?

@cosmo0920
Copy link
Contributor

cosmo0920 commented Aug 18, 2025

This is already done on fluent/chunkio#109.

We need to sync the latest chunkio from its upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants