Skip to content

Commit

Permalink
open & write: Process regular files only
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed May 12, 2024
1 parent bf15fdd commit 3510fcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ func LoadInput(args []string) []*buffer.Buffer {
// Option 1
// We go through each file and load it
for i := 0; i < len(files); i++ {
buf, err := buffer.NewBufferFromFileAtLoc(files[i], btype, flagStartPos)
file := files[i]
fileInfo, _ := os.Stat(file)
if !fileInfo.Mode().IsRegular() {
screen.TermMessage("No regular file: " + file)
continue
}
buf, err := buffer.NewBufferFromFileAtLoc(file, btype, flagStartPos)
if err != nil {
screen.TermMessage(err)
continue
Expand Down
7 changes: 5 additions & 2 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,17 @@ func resolvePath(filename string) (string, error) {
for {
// We use Stat() as trick to let the OS do symlink loop detection for us,
// since we are lazy to do it ourselves
_, err := os.Stat(filename)
fileInfo, err := os.Stat(filename)
if errors.Is(err, fs.ErrNotExist) {
return filename, nil
}
if err != nil {
return filename, err
}
fileInfo, err := os.Lstat(filename)
if !fileInfo.Mode().IsRegular() {
return filename, errors.New("No regular file: " + filename)
}
fileInfo, err = os.Lstat(filename)
if err != nil {
return filename, err
}
Expand Down

0 comments on commit 3510fcc

Please sign in to comment.