Skip to content

Commit

Permalink
address pr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed Sep 28, 2023
1 parent 5d57495 commit fca8d75
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion libbeat/processors/cache/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -224,7 +225,7 @@ func (c *fileStore) writeState(final bool) {
}
return
}
f, err := os.CreateTemp(filepath.Dir(c.path), "")
f, err := os.CreateTemp(filepath.Dir(c.path), cleanFilename(c.id)+"-*.tmp")
if err != nil {
c.log.Errorw("failed to open file to write state", "error", err)
return
Expand Down Expand Up @@ -270,3 +271,24 @@ func (c *fileStore) writeState(final bool) {
}
}
}

// cleanFilename replaces illegal printable characters (and space or dot) in
// filenames, with underscore.
func cleanFilename(s string) string {
return pathCleaner.Replace(s)
}

var pathCleaner = strings.NewReplacer(
"/", "_",
"<", "_",
">", "_",
":", "_",
`"`, "_",
"/", "_",
`\`, "_",
"|", "_",
"?", "_",
"*", "_",
".", "_",
" ", "_",
)

0 comments on commit fca8d75

Please sign in to comment.