diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-20 22:21:28 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-20 22:21:28 -0700 |
| commit | f22acf38da970aa0d865a9978c9499dad01d235f (patch) | |
| tree | 6811766749c794afd9eb23e372cc1673f1bae41a /hotline/files.go | |
| parent | 7cd900d61edbd6d322db3cecb913adf574389320 (diff) | |
Convert hardcoded path separators to filepath.Join
Diffstat (limited to 'hotline/files.go')
| -rw-r--r-- | hotline/files.go | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/hotline/files.go b/hotline/files.go index b66580f..dc19653 100644 --- a/hotline/files.go +++ b/hotline/files.go @@ -10,17 +10,9 @@ import ( "strings" ) -func downcaseFileExtension(filename string) string { - splitStr := strings.Split(filename, ".") - ext := strings.ToLower( - splitStr[len(splitStr)-1], - ) - - return ext -} - -func fileTypeFromFilename(fn string) fileType { - ft, ok := fileTypes[downcaseFileExtension(fn)] +func fileTypeFromFilename(filename string) fileType { + fileExt := strings.ToLower(filepath.Ext(filename)) + ft, ok := fileTypes[fileExt] if ok { return ft } @@ -38,8 +30,8 @@ func fileTypeFromInfo(info fs.FileInfo) (ft fileType, err error) { return ft, nil } -func getFileNameList(filePath string) (fields []Field, err error) { - files, err := os.ReadDir(filePath) +func getFileNameList(path string) (fields []Field, err error) { + files, err := os.ReadDir(path) if err != nil { return fields, nil } @@ -59,12 +51,12 @@ func getFileNameList(filePath string) (fields []Field, err error) { } if fileInfo.Mode()&os.ModeSymlink != 0 { - resolvedPath, err := os.Readlink(filePath + "/" + file.Name()) + resolvedPath, err := os.Readlink(filepath.Join(path, file.Name())) if err != nil { return fields, err } - rFile, err := os.Stat(filePath + "/" + resolvedPath) + rFile, err := os.Stat(filepath.Join(path, resolvedPath)) if errors.Is(err, os.ErrNotExist) { continue } @@ -73,7 +65,7 @@ func getFileNameList(filePath string) (fields []Field, err error) { } if rFile.IsDir() { - dir, err := ioutil.ReadDir(filePath + "/" + file.Name()) + dir, err := ioutil.ReadDir(filepath.Join(path, file.Name())) if err != nil { return fields, err } @@ -95,7 +87,7 @@ func getFileNameList(filePath string) (fields []Field, err error) { } } else if file.IsDir() { - dir, err := ioutil.ReadDir(filePath + "/" + file.Name()) + dir, err := ioutil.ReadDir(filepath.Join(path, file.Name())) if err != nil { return fields, err } @@ -116,7 +108,7 @@ func getFileNameList(filePath string) (fields []Field, err error) { continue } - hlFile, err := newFileWrapper(&OSFileStore{}, filePath+"/"+file.Name(), 0) + hlFile, err := newFileWrapper(&OSFileStore{}, path+"/"+file.Name(), 0) if err != nil { return nil, err } |