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

Open absolute paths as files, limited Windows support #1159

Merged
merged 5 commits into from Sep 12, 2022

Conversation

prashantv
Copy link
Collaborator

Ref #994, #1000

Alternate approach to #999, this approach brings absolute path support to Windows.
It does so by checking for absolute paths and handling them using the file factory directly.

To test different paths without trying to actually open them (UNC paths hit the network), this change also
prefactors the sink registry into a separate type that allows stubbing of the os.OpenFile call.

Note: This change does not bring full Windows support -- many tests still fail, and Windows file URIs don't work.

@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Merging #1159 (15c26e5) into master (7681a0a) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1159      +/-   ##
==========================================
+ Coverage   98.24%   98.34%   +0.09%     
==========================================
  Files          49       49              
  Lines        2165     2169       +4     
==========================================
+ Hits         2127     2133       +6     
+ Misses         29       28       -1     
+ Partials        9        8       -1     
Impacted Files Coverage Δ
sink.go 100.00% <100.00%> (ø)
writer.go 100.00% <100.00%> (ø)
zapcore/sampler.go 100.00% <0.00%> (+3.70%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Thanks! No blockers, left a few suggestions.

sink.go Show resolved Hide resolved
sink_test.go Outdated Show resolved Hide resolved
sink.go Outdated Show resolved Hide resolved
sink_windows_test.go Outdated Show resolved Hide resolved
This makes it easier to test sinkRegistry functionality that registers
temporary sinks, and in future, stubbing of the os.OpenFile call.
This avoids a dependency on the underlying filesystem, which avoids
unnecessarily trying to open files when we just want to ensure that
paths are opened using the file sink.
Windows absolute paths such as `c:\log.json` parse as URLs with
the scheme set. The sink registry currently expects file paths
to either have a `file` scheme, or no scheme. Rather than trying to
special-case drives in schemes, and reassemble paths, simplify by
checking for `filepath.IsAbs` before parsing the path as a URL.

Since `filepath.IsAbs` is OS-specific, windows paths will not be
treated as absolute paths on other systems, and will still work
using any registered sink factories.
@prashantv
Copy link
Collaborator Author

Thanks for the suggestions, updated to incorporate them.

@abhinav abhinav merged commit 7cabba7 into uber-go:master Sep 12, 2022
@prashantv prashantv deleted the prashantv/zap-win-abs branch September 12, 2022 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants