Skip to content

glob: fix glob function and extract as win32 utility file#11165

Open
zshuang0316 wants to merge 3 commits intofluent:masterfrom
zshuang0316:patch-4
Open

glob: fix glob function and extract as win32 utility file#11165
zshuang0316 wants to merge 3 commits intofluent:masterfrom
zshuang0316:patch-4

Conversation

@zshuang0316
Copy link
Contributor

@zshuang0316 zshuang0316 commented Nov 15, 2025

Set context glob path size correctly.


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:

  • [ N/A] Example configuration file for the change
  • Debug log output from testing the change
    [2025/11/15 17:48:33] [debug] [input:blob:blob.0] scanning path C:\data\Logs\local*.log
    [2025/11/15 17:48:33] [ info] [input:blob:blob.0] DEBUG: recursive_file_search called with path='NULL' pattern='C:\data\Logs\local*.log'
    [2025/11/15 17:48:33] [ info] [input:blob:blob.0] DEBUG: calling glob with local_pattern='C:\data\Logs\local*.log'
    [2025/11/15 17:48:33] [ info] [input:blob:blob.0] DEBUG: glob returned 0, found 14 matches
  • 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.

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

Documentation

  • [ N/A] 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

  • New Features

    • Windows now exposes a POSIX-like globbing API for file pattern matching via a dedicated header.
  • Refactor

    • Windows glob behavior externalized to a header-backed implementation and simplified public surface.
  • Bug Fixes

    • Corrected directory-detection logic in Windows globbing.
  • Tests

    • Added Windows-only unit tests for basic matches, no-match cases, and wildcards.
  • Chores

    • Updated Windows build and test configuration to include the new glob support.

@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2025

📝 Walkthrough

Walkthrough

Switches Windows glob from an unconditional source-include to a guarded header/API (flb_glob_win32.h), moves Windows glob implementation into src/win32/flb_glob.c, updates CMake and tests to include Windows sources, and exposes glob, globfree, and is_directory for Windows.

Changes

Cohort / File(s) Summary
Windows Glob API Header
include/fluent-bit/flb_glob_win32.h
Adds Windows-only header exposing glob flags, error codes, FLB_FILE_MAX_PATH_LENGTH, public structs, a glob_t typedef and declarations for glob, globfree, and is_directory.
Windows Glob Implementation
src/win32/flb_glob.c
Reworks Windows implementation to rely on the new header, removes internal typedefs/macros, makes globfree and is_directory non-static, and adapts inner-context handling to header types.
Build Configuration
src/CMakeLists.txt, tests/internal/CMakeLists.txt
Adds win32/flb_glob.c to Windows build sources and registers tests/internal/win32_glob.c in the Windows-only test block.
Plugin include change
plugins/in_blob/blob.c
Replaces unconditional inclusion of a Windows source file with a #ifdef FLB_SYSTEM_WINDOWS include of <fluent-bit/flb_glob_win32.h>.
Windows Unit Tests
tests/internal/win32_glob.c
Adds Windows-only unit tests (test_glob_basic, test_glob_nomatch, test_glob_wildcard) and a Windows-guarded TEST_LIST registration.

Sequence Diagram(s)

sequenceDiagram
    participant Plugin as Plugin (plugins/in_blob/blob.c)
    participant GlobAPI as Glob API (flb_glob_win32.h / src/win32/flb_glob.c)
    participant FS as Filesystem
    Plugin->>GlobAPI: glob(pattern, flags, NULL, &ctx)
    GlobAPI->>FS: enumerate matching paths / stat entries
    FS-->>GlobAPI: entries & metadata
    GlobAPI-->>Plugin: return results (ctx->gl_pathv, ctx->gl_pathc) / status
    Plugin->>GlobAPI: globfree(&ctx)
    GlobAPI-->>Plugin: free resources
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • edsiper
  • patrick-stephens
  • niedbalski
  • celalettin1286

Poem

🐇 I hopped through headers, tests, and code,
Windows globs found a tidy new road.
Patterns matched and contexts freed,
Paths returned as promises kept.
A rabbit cheers — small changes, neat deed.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing the glob function and extracting it as a reusable win32 utility file, which aligns with the substantial refactoring across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
plugins/in_blob/win32_glob.c (1)

107-117: Consider defensive cleanup in globfree.

For consistency and defensive programming, consider:

  1. Setting context->gl_pathc = 0 after freeing gl_pathv
  2. Removing the unused index variable declared on line 109

These changes would make the cleanup more complete and remove dead code.

 static void globfree(glob_t *context)
 {
-    size_t index;
-
     if (context->gl_pathv != NULL) {
         flb_free(context->gl_pathv);
         context->gl_pathv = NULL;
+        context->gl_pathc = 0;
     }

     flb_file_glob_clean(&context->inner_context);
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1ba23a and b1381a1.

📒 Files selected for processing (1)
  • plugins/in_blob/win32_glob.c (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (31)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COMPILER_STRICT_POINTER_TYPES=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
🔇 Additional comments (2)
plugins/in_blob/win32_glob.c (2)

153-153: Essential fix: properly exposes the match count.

This correctly sets gl_pathc to the number of matched paths after populating gl_pathv. Without this assignment, callers would have no way to determine how many entries are in the path array, breaking the glob functionality on Windows.


608-608: Good practice: file ends with newline.

This formatting improvement aligns with standard coding conventions.

Copy link
Contributor

@cosmo0920 cosmo0920 left a comment

Choose a reason for hiding this comment

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

It looks good to me.

@zshuang0316
Copy link
Contributor Author

@coderabbitai help could you guide me how to re-run the failed checks? I think they should not relate to my change.

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the status of checks/CI runs on this PR
gh pr view 11165 --repo fluent/fluent-bit --json statusCheckRollup,commits | jq '.'

Length of output: 22891


🏁 Script executed:

#!/bin/bash
# Get more details about the PR including check runs
gh api repos/fluent/fluent-bit/pulls/11165/commits | jq '.[-1].sha' -r | xargs -I {} gh api repos/fluent/fluent-bit/commits/{}/check-runs | jq '.check_runs[] | {name: .name, status: .status, conclusion: .conclusion, html_url: .html_url}'

Length of output: 6507


🏁 Script executed:

#!/bin/bash
# Check if there are any workflow runs for this PR
gh run list --repo fluent/fluent-bit --branch patch-4 --limit 10 --json databaseId,status,conclusion,name,event,createdAt,workflowName,url

Length of output: 2445


@zshuang0316, you're correct that the failed check is unrelated to your Windows-specific changes. Let me explain what happened and how to re-run the checks.

What Failed

The only failing check is:

This is a Linux unit test with the undefined behavior sanitizer enabled. Your changes are in plugins/in_blob/win32_glob.c, which is Windows-specific code, so this failure is definitely unrelated to your PR.

Good News

All Windows-related checks passed successfully:

  • ✅ Windows 32bit build and tests
  • ✅ Windows 64bit build and tests
  • ✅ Windows 64bit (Arm64) build and tests

How to Re-run Failed Checks

You have a few options:

Option 1: Ask a Maintainer

Since you've already tagged maintainers as reviewers (@edsiper, @cosmo0920), you can ask them to re-run the failed checks. Maintainers can click the "Re-run failed jobs" button in the Actions tab.

Option 2: Push an Empty Commit (if you have write access)

git commit --allow-empty -m "chore: trigger CI re-run"
git push

Option 3: Wait for Maintainer Review

Often maintainers will recognize flaky tests and either re-run them or merge the PR knowing the failure is unrelated.

Recommendation

I suggest commenting on your PR mentioning the maintainers and noting that the failing test is a Linux sanitizer test unrelated to your Windows-specific fix, and all Windows checks passed. They can then re-run the failed job or proceed with the merge.

Would you like me to help you draft a comment for the maintainers?

@zshuang0316
Copy link
Contributor Author

Hello @cosmo0920, could you please help on the failed linux check which should not related to the code change? Thanks!

@cosmo0920
Copy link
Contributor

Hello @cosmo0920, could you please help on the failed linux check which should not related to the code change? Thanks!

This is not related to your changes. But this type of errors are already eliminated in the current master. So, could you rebase off master? Then, this type of error will be gone.

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

🧹 Nitpick comments (1)
plugins/in_blob/win32_glob.c (1)

107-117: Consider resetting gl_pathc in globfree for consistency.

While not strictly required (POSIX allows glob_t contents to be undefined after globfree), resetting gl_pathc = 0 alongside gl_pathv = NULL would be more defensive and consistent.

Apply this diff:

 static void globfree(glob_t *context)
 {
     size_t index;
 
     if (context->gl_pathv != NULL) {
         flb_free(context->gl_pathv);
         context->gl_pathv = NULL;
     }
+
+    context->gl_pathc = 0;
 
     flb_file_glob_clean(&context->inner_context);
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1381a1 and 83635f9.

📒 Files selected for processing (1)
  • plugins/in_blob/win32_glob.c (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (31)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COMPILER_STRICT_POINTER_TYPES=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (1)
plugins/in_blob/win32_glob.c (1)

153-153: Essential fix: correctly exposes the match count.

This assignment is critical for the glob API to function correctly. Without it, callers have no way to determine how many paths are in gl_pathv, rendering the implementation unusable. The placement after successful population of the array is correct, and the value accurately reflects the number of matches found.

@zshuang0316
Copy link
Contributor Author

This commit fails the automated prefix validation check due to a limitation in the validation script when handling cross-component refactorings.
Why the validation fails: The commit touches multiple components (in_blob:, win32:, tests:, build:). The validation script requires either:

* A single component prefix when only one component is modified, OR

* An umbrella prefix (lib: or tests:) when ALL files are within that directory

Since this refactoring necessarily spans multiple directories to extract shared Windows functionality, neither condition can be satisfied. I chose "win32:" as the prefix since it best represents the primary purpose of the change.
@cosmo0920 I mistakenly rebase master and the check cannot pass.

Your commit includes lots of components. So, our linter almost always complains about this. I recommend you to split two of the commits at least. One is for implementation and the other is for adding unit testing files.

This commit fails the automated prefix validation check due to a limitation in the validation script when handling cross-component refactorings.
Why the validation fails: The commit touches multiple components (in_blob:, win32:, tests:, build:). The validation script requires either:

* A single component prefix when only one component is modified, OR

* An umbrella prefix (lib: or tests:) when ALL files are within that directory

Since this refactoring necessarily spans multiple directories to extract shared Windows functionality, neither condition can be satisfied. I chose "win32:" as the prefix since it best represents the primary purpose of the change.
@cosmo0920 I mistakenly rebase master and the check cannot pass.

Your commit includes lots of components. So, our linter almost always complains about this. I recommend you to split two of the commits at least. One is for implementation and the other is for adding unit testing files.

@cosmo0920 Thanks for your advice! I split it to three commits, now it looks good.

Signed-off-by: zshuang0316 <zshuang0316@163.com>
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