replace imports of path with path/filepath (#2330)

This commit is contained in:
mmetc 2023-07-26 10:29:58 +02:00 committed by GitHub
parent 1a6f12c88e
commit a01ce18b98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 21 deletions

View file

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
@ -116,7 +115,7 @@ title: %s
---
`
name := filepath.Base(filename)
base := strings.TrimSuffix(name, path.Ext(name))
base := strings.TrimSuffix(name, filepath.Ext(name))
return fmt.Sprintf(header, base, strings.ReplaceAll(base, "_", " "))
}

View file

@ -4,7 +4,7 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"testing"
@ -43,7 +43,7 @@ func (s *PluginSuite) SetupSuite() {
s.buildDir, err = os.MkdirTemp("", "cs_plugin_test_build")
require.NoError(t, err)
s.builtBinary = path.Join(s.buildDir, "notification-dummy")
s.builtBinary = filepath.Join(s.buildDir, "notification-dummy")
if runtime.GOOS == "windows" {
s.builtBinary += ".exe"
@ -101,15 +101,15 @@ func (s *PluginSuite) SetupSubTest() {
s.runDir, err = os.MkdirTemp("", "cs_plugin_test")
require.NoError(t, err)
s.pluginDir = path.Join(s.runDir, "bin")
err = os.MkdirAll(path.Join(s.runDir, "bin"), 0o755)
s.pluginDir = filepath.Join(s.runDir, "bin")
err = os.MkdirAll(filepath.Join(s.runDir, "bin"), 0o755)
require.NoError(t, err, "while creating bin dir")
s.notifDir = path.Join(s.runDir, "config")
s.notifDir = filepath.Join(s.runDir, "config")
err = os.MkdirAll(s.notifDir, 0o755)
require.NoError(t, err, "while creating config dir")
s.pluginBinary = path.Join(s.pluginDir, "notification-dummy")
s.pluginBinary = filepath.Join(s.pluginDir, "notification-dummy")
if runtime.GOOS == "windows" {
s.pluginBinary += ".exe"
@ -120,7 +120,7 @@ func (s *PluginSuite) SetupSubTest() {
err = os.Chmod(s.pluginBinary, 0o744)
require.NoError(t, err, "chmod 0744 %s", s.pluginBinary)
s.pluginConfig = path.Join(s.notifDir, "dummy.yaml")
s.pluginConfig = filepath.Join(s.notifDir, "dummy.yaml")
err = copyFile("testdata/dummy.yaml", s.pluginConfig)
require.NoError(t, err, "while copying plugin config")
}

View file

@ -5,7 +5,7 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
log "github.com/sirupsen/logrus"
@ -58,7 +58,7 @@ func downloadFile(url string, destPath string) error {
func GetData(data []*types.DataSource, dataDir string) error {
for _, dataS := range data {
destPath := path.Join(dataDir, dataS.DestPath)
destPath := filepath.Join(dataDir, dataS.DestPath)
log.Infof("downloading data '%s' in '%s'", dataS.SourceURL, destPath)
err := downloadFile(dataS.SourceURL, destPath)
if err != nil {

View file

@ -8,7 +8,6 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"strings"
@ -266,7 +265,7 @@ func downloadData(dataFolder string, force bool, reader io.Reader) error {
download := false
for _, dataS := range data.Data {
if _, err := os.Stat(path.Join(dataFolder, dataS.DestPath)); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(dataFolder, dataS.DestPath)); os.IsNotExist(err) {
download = true
}
}

View file

@ -7,7 +7,7 @@ import (
"net"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
@ -128,7 +128,7 @@ func UpdateRegexpCacheMetrics() {
func FileInit(fileFolder string, filename string, fileType string) error {
log.Debugf("init (folder:%s) (file:%s) (type:%s)", fileFolder, filename, fileType)
filepath := path.Join(fileFolder, filename)
filepath := filepath.Join(fileFolder, filename)
file, err := os.Open(filepath)
if err != nil {
return err

View file

@ -9,7 +9,7 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"time"
@ -311,7 +311,7 @@ func (m *Metabase) DumpConfig(path string) error {
func (m *Metabase) DownloadDatabase(force bool) error {
metabaseDBSubpath := path.Join(m.Config.DBPath, "metabase.db")
metabaseDBSubpath := filepath.Join(m.Config.DBPath, "metabase.db")
_, err := os.Stat(metabaseDBSubpath)
if err == nil && !force {
log.Printf("%s exists, skip.", metabaseDBSubpath)
@ -383,5 +383,5 @@ func (m *Metabase) ExtractDatabase(buf *bytes.Reader) error {
}
func RemoveDatabase(dataDir string) error {
return os.RemoveAll(path.Join(dataDir, "metabase.db"))
return os.RemoveAll(filepath.Join(dataDir, "metabase.db"))
}

View file

@ -3,7 +3,7 @@ package parser
import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"
@ -46,7 +46,7 @@ func Init(c map[string]interface{}) (*UnixParserCtx, error) {
if strings.Contains(f.Name(), ".") {
continue
}
if err := r.Grok.AddFromFile(path.Join(c["patterns"].(string), f.Name())); err != nil {
if err := r.Grok.AddFromFile(filepath.Join(c["patterns"].(string), f.Name())); err != nil {
log.Errorf("failed to load pattern %s : %v", f.Name(), err)
return nil, err
}
@ -97,7 +97,7 @@ func NewParsers() *Parsers {
func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, error) {
var err error
patternsDir := path.Join(cConfig.Crowdsec.ConfigDir, "patterns/")
patternsDir := filepath.Join(cConfig.Crowdsec.ConfigDir, "patterns/")
log.Infof("Loading grok library %s", patternsDir)
/* load base regexps for two grok parsers */
parsers.Ctx, err = Init(map[string]interface{}{"patterns": patternsDir,