Skip to content

Commit 84d9f48

Browse files
authored
[receiver/filelog][pkg/stanza] Prevent a lot of errors on windows if the path contains Junction (#20732)
* Prevent a lot of errors on windows if the path contains Junction
1 parent 144b342 commit 84d9f48

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: pkg/stanza
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Fix errors in loop evaluating file attributes on windows if the file path contains a Junction
9+
10+
# One or more tracking issues related to the change
11+
issues: [21088]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

pkg/stanza/fileconsumer/attributes.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package fileconsumer // import "github.com/open-telemetry/opentelemetry-collecto
1616

1717
import (
1818
"path/filepath"
19+
"runtime"
1920

2021
"go.uber.org/multierr"
2122
)
@@ -36,7 +37,15 @@ func (f *FileAttributes) HeaderAttributesCopy() map[string]any {
3637
// resolveFileAttributes resolves file attributes
3738
// and sets it to empty string in case of error
3839
func resolveFileAttributes(path string) (*FileAttributes, error) {
39-
resolved, symErr := filepath.EvalSymlinks(path)
40+
resolved := ""
41+
var symErr error
42+
// Dirty solution, waiting for this permanent fix https://github.com/golang/go/issues/39786
43+
// EvalSymlinks on windows is partially working depending on the way you use Symlinks and Junctions
44+
if runtime.GOOS != "windows" {
45+
resolved, symErr = filepath.EvalSymlinks(path)
46+
} else {
47+
resolved = path
48+
}
4049
abs, absErr := filepath.Abs(resolved)
4150

4251
return &FileAttributes{

0 commit comments

Comments
 (0)