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

[receiver/filelog][pkg/stanza] Prevent a lot of errors on windows if the path contains Junction #20732

Merged
merged 16 commits into from
Apr 26, 2023
16 changes: 16 additions & 0 deletions .chloggen/filelogreceiver-fix-windows-symlinks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/stanza

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix errors in loop evaluating file attributes on windows if the file path contains a Junction

# One or more tracking issues related to the change
issues: [21088]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
11 changes: 10 additions & 1 deletion pkg/stanza/fileconsumer/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package fileconsumer // import "github.com/open-telemetry/opentelemetry-collecto

import (
"path/filepath"
"runtime"

"go.uber.org/multierr"
)
Expand All @@ -36,7 +37,15 @@ func (f *FileAttributes) HeaderAttributesCopy() map[string]any {
// resolveFileAttributes resolves file attributes
// and sets it to empty string in case of error
func resolveFileAttributes(path string) (*FileAttributes, error) {
resolved, symErr := filepath.EvalSymlinks(path)
resolved := ""
var symErr error
// Dirty solution, waiting for this permanent fix https://github.com/golang/go/issues/39786
// EvalSymlinks on windows is partially working depending on the way you use Symlinks and Junctions
gillg marked this conversation as resolved.
Show resolved Hide resolved
if runtime.GOOS != "windows" {
resolved, symErr = filepath.EvalSymlinks(path)
} else {
resolved = path
}
abs, absErr := filepath.Abs(resolved)

return &FileAttributes{
Expand Down