Skip to content

Commit

Permalink
Merge pull request #1402 from cogentcore/fileinfo
Browse files Browse the repository at this point in the history
fileinfo: only get mimeinfo and generated from regular files
  • Loading branch information
kkoreilly authored Dec 25, 2024
2 parents 8b26e9d + 85e505b commit 3bf7f7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- name: Build
run: go build -v ./...

- name: Build Docs (to verify it works on PRs)
run: core build web -dir docs -o static

# we can't test gpu, xyz, and system on the CI since there is no Vulkan support
- name: Test
run: go test -v $(go list ./... | grep -v gpu | grep -v xyz | grep -v system) -coverprofile cover.out -timeout 30s
Expand Down
16 changes: 11 additions & 5 deletions base/fileinfo/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func NewFileInfoType(ftyp Known) *FileInfo {
// but file info will be updated based on the filename even if
// the file does not exist.
func (fi *FileInfo) InitFile(fname string) error {
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Generated = false
fi.Kind = ""
var errs []error
path, err := filepath.Abs(fname)
if err == nil {
Expand All @@ -111,7 +115,6 @@ func (fi *FileInfo) InitFile(fname string) error {
fi.Path = fname
}
_, fi.Name = filepath.Split(path)
fi.SetMimeInfo()
info, err := os.Stat(fi.Path)
if err != nil {
errs = append(errs, err)
Expand All @@ -126,10 +129,13 @@ func (fi *FileInfo) InitFile(fname string) error {
// but file info will be updated based on the filename even if
// the file does not exist.
func (fi *FileInfo) InitFileFS(fsys fs.FS, fname string) error {
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Generated = false
fi.Kind = ""
var errs []error
fi.Path = fname
_, fi.Name = path.Split(fname)
fi.SetMimeInfo()
info, err := fs.Stat(fsys, fi.Path)
if err != nil {
errs = append(errs, err)
Expand All @@ -145,10 +151,7 @@ func (fi *FileInfo) SetMimeInfo() error {
if fi.Path == "" || fi.Path == "." || fi.IsDir() {
return nil
}
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Generated = IsGeneratedFile(fi.Path)
fi.Kind = ""
mtyp, _, err := MimeFromFile(fi.Path)
if err != nil {
return err
Expand Down Expand Up @@ -177,6 +180,9 @@ func (fi *FileInfo) SetFileInfo(info fs.FileInfo) {
fi.Cat = Folder
fi.Known = AnyFolder
} else {
if fi.Mode.IsRegular() {
fi.SetMimeInfo()
}
if fi.Cat == UnknownCategory {
if fi.IsExec() {
fi.Cat = Exe
Expand Down

0 comments on commit 3bf7f7e

Please sign in to comment.