Skip to content

Commit f26a077

Browse files
committed
fix(Open): handle non-regular file
1 parent 15b6fd6 commit f26a077

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

errors.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tailpipe
2+
3+
import "errors"
4+
5+
var (
6+
// ErrNotSupported is returned when an operation is attempted on an underlying stream that does not support it.
7+
ErrNotSupported = errors.New("operation not supported by underlying stream")
8+
9+
// ErrNotRegularFile is returned when a provided file is not a regular file.
10+
ErrNotRegularFile = errors.New("provided file is not a regular file")
11+
)

tailpipe.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
package tailpipe
66

77
import (
8-
"errors"
98
"io"
109
"os"
1110
"sync"
1211
"time"
1312
)
1413

15-
// The Follow function allows for the creation of a File with an underlying
16-
// stream that may not implement all interfaces which a File implements. Such
17-
// Files will return ErrNotSupported when this is the case.
18-
var ErrNotSupported = errors.New("Operation not supported by underlying stream")
19-
2014
// A File represents an open normal file. A File is effectively of infinite
2115
// length; all reads to the file will block until data are available,
2216
// even if EOF on the underlying file is reached.
@@ -102,6 +96,16 @@ func Open(path string) (*File, error) {
10296
if err != nil {
10397
return nil, err
10498
}
99+
100+
fi, err := f.Stat()
101+
if err != nil {
102+
return nil, err
103+
}
104+
105+
if !fi.Mode().IsRegular() {
106+
return nil, ErrNotRegularFile
107+
}
108+
105109
return Follow(f), err
106110
}
107111

0 commit comments

Comments
 (0)