Skip to content

Commit

Permalink
programkind: quietly skip non-file files (#529)
Browse files Browse the repository at this point in the history
* programkind: quietly skip non-file files

* add error handling
  • Loading branch information
tstromberg authored Oct 18, 2024
1 parent fde0469 commit 35604a9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/programkind/programkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -93,6 +94,18 @@ func makeFileType(path string, ext string, mime string) *FileType {

// File detects what kind of program this file might be.
func File(path string) (*FileType, error) {
st, err := os.Stat(path)
if err != nil {
return nil, fmt.Errorf("stat: %w", err)
}

if st.IsDir() {
return nil, nil
}
if st.Mode().Type() == fs.ModeIrregular {
return nil, nil
}

// first strategy: mimetype
mtype, err := mimetype.DetectFile(path)
if err == nil {
Expand Down

0 comments on commit 35604a9

Please sign in to comment.