Skip to content

Commit

Permalink
[receiver/filelog][pkg/stanza] Prevent a lot of errors on windows if …
Browse files Browse the repository at this point in the history
…the path contains Junction (open-telemetry#20732)

* Prevent a lot of errors on windows if the path contains Junction
  • Loading branch information
gillg authored Apr 26, 2023
1 parent 144b342 commit 84d9f48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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
if runtime.GOOS != "windows" {
resolved, symErr = filepath.EvalSymlinks(path)
} else {
resolved = path
}
abs, absErr := filepath.Abs(resolved)

return &FileAttributes{
Expand Down

0 comments on commit 84d9f48

Please sign in to comment.