Skip to content
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

fix: broken embedio on windows #1135

Open
wants to merge 3 commits into
base: gh-windows
Choose a base branch
from

Conversation

jabdr
Copy link
Contributor

@jabdr jabdr commented Aug 24, 2024

At the moment loadFromFile and parser.FromFile fail on windows if fs.Sub filesystem is used. This is due to the different behaviour related to filepath.Seperator and absolute paths.

This patch fixes TestEmbedFS, TestLoadFromFileAbsolutePath and TestLoadFromCustomFS on windows.

As loadFromFile and Parser.FromFile are not related to each other, it made more sense to me, to put the common code into the io package.

@jabdr jabdr marked this pull request as ready for review August 24, 2024 17:14
@jabdr jabdr requested a review from a team as a code owner August 24, 2024 17:14
Copy link

codecov bot commented Aug 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (gh-windows@0c0eed6). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff              @@
##             gh-windows    #1135   +/-   ##
=============================================
  Coverage              ?   83.14%           
=============================================
  Files                 ?      164           
  Lines                 ?     7688           
  Branches              ?        0           
=============================================
  Hits                  ?     6392           
  Misses                ?     1042           
  Partials              ?      254           
Flag Coverage Δ
default 83.14% <100.00%> (?)
examples 83.14% <100.00%> (?)
ftw 83.14% <100.00%> (?)
ftw-multiphase 83.14% <100.00%> (?)
tinygo 83.14% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -0,0 +1,15 @@
package io
Copy link
Member

Choose a reason for hiding this comment

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

This is missing our license header

Copy link
Member

Choose a reason for hiding this comment

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

Also, having a whole package for a single function looks like an overkill

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The io package already exists. The other files did not seem appropriate in this package, so I choose a new. If you wish a different approach, then please give a more detailed description of what you have in mind.

internal/io/embedio.go Outdated Show resolved Hide resolved
internal/io/embedio.go Outdated Show resolved Hide resolved
)

// FSReadFile wraps fs.ReadFile supporting embedio on windows
func FSReadFile(fsys fs.FS, name string) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

wonder why io and not fs package since it wraps a fs function

Copy link
Member

@jcchavezs jcchavezs left a comment

Choose a reason for hiding this comment

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

I would not change the FSReadFile for non windows, instead I would define a global variable for this function, use default one for non windows systems and use a custom one for windows (under a build tag, you can use _windows.go suffix swell) and then enable windows on CI.

Since several changes will happen before windows CI is green I would create a branch windows_support and merge all this PRs against that branch.

All that said, thanks a lot for all this effort!

@jabdr
Copy link
Contributor Author

jabdr commented Aug 28, 2024

@jcchavezs On non windows systems the if clause is optimized away by the compiler and on windows it is just always used (filepath.Seperator is already a const). Using a variable and build tags would make it more complicated in my opinion.

i used the internal/io package, because it already existed. I don't see any internal/fs package.

@jcchavezs
Copy link
Member

Despite the performance impact, I'd rather not add ifs that pollutes the code and instead abstract that off into a os dependent file.

@jabdr
Copy link
Contributor Author

jabdr commented Aug 28, 2024

@jcchavezs done

@jcchavezs jcchavezs changed the base branch from main to gh-windows October 2, 2024 19:19
@jcchavezs
Copy link
Member

Please rebase your PR on top of gh-windows

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.

3 participants