Skip to content

fix: cache path checks across Windows volumes - #35

Merged
bobg merged 4 commits into
bobg:mainfrom
WoozyMasta:fix/windows-cache
Jul 24, 2026
Merged

fix: cache path checks across Windows volumes#35
bobg merged 4 commits into
bobg:mainfrom
WoozyMasta:fix/windows-cache

Conversation

@WoozyMasta

@WoozyMasta WoozyMasta commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

filepath.Rel returns an error on Windows when the cache directory and scanned source file are located on different volumes.
That condition means the source file is not inside cache and should not abort scan.

Changes:

  • treats paths on different volumes as outside cache
  • uses platform-aware lexical containment checks
  • fixes same-volume Windows paths using backslash separators
  • adds Windows-specific regression tests
  • runs test suite on Windows in CI

Fixes #17

@WoozyMasta WoozyMasta changed the title Fix/windows cache fix: cache path checks across Windows volumes Jul 15, 2026
@WoozyMasta

Copy link
Copy Markdown
Contributor Author

Hi @bobg, thanks for maintaining mingo.

Workflow is currently awaiting maintainer approval. Could you approve and review it?

@bobg bobg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for this patch! I have one requested change.

Comment thread scan.go Outdated
rel, err := filepath.Rel(dir, filename)
if err != nil {
return false, errors.Wrapf(err, "computing relative path from %s to %s", cacheDir, filename)
return false

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

As you observe, if dir and filename are in different Windows volumes, filepath.Rel will return an error. But that doesn't mean that all errors from filepath.Rel mean "different volumes." I'd rather not ignore those possible other errors.

How about explicitly detecting the separate-volumes condition using filepath.VolumeName?

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.

You're absolutely right, I missed that. It's now fixed, thanks for pointing it out!

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

This PR fixes Windows scanning failures when GOCACHE is on a different volume than the module being scanned by avoiding filepath.Rel errors across volumes and using a safer lexical containment check to decide whether a file is inside the cache directory.

Changes:

  • Replace the cache containment check with a new isWithinDir helper that treats different Windows volumes as “outside” and uses filepath.IsLocal on the relative path.
  • Add cross-platform and Windows-specific regression tests for directory containment behavior.
  • Update CI to run the Go test suite on both Linux and Windows, while keeping coverage/modver steps Linux-only.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
scan.go Refactors cache containment logic to handle Windows multi-volume paths and separator semantics safely.
scan_test.go Adds general regression tests for lexical containment edge cases (parent/sibling/common-prefix).
scan_windows_test.go Adds Windows-only tests covering different-volume and same-volume containment cases.
.github/workflows/go.yml Runs tests on Windows via a job matrix; gates coverage/modver to Linux to avoid duplicate runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bobg

bobg commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Apologies for the failing test - it comes from my Modver tool and, as I've just learned, it's because GitHub refuses to honor the issues: write permission in the workflow file when the PR originates from a fork.

I'm going to make a change to the Modver workflow and then ask you to merge it into your PR. It'll take me a day or two, please bear with me. Thanks!

(This is separate from the problem with the canceled Windows test, which I don't understand - do you?)

@bobg bobg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you again for this change! My changes to the Modver workflow are taking longer than I planned, but they don't have to block this PR any longer. (Also, I now understand the Windows test failure: it was canceled when the Linux test failed.) Cheers!

@bobg
bobg merged commit 6411658 into bobg:main Jul 24, 2026
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scanning directory on other drive fails on Windows

3 participants