Fixed the enduring nasty "too many files open" bug!! Fix #446
This commit is contained in:
Vendored
+5
@@ -121,6 +121,7 @@ func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {
|
||||
return &CachedStream{
|
||||
Reader: sr,
|
||||
Seeker: sr,
|
||||
Closer: r,
|
||||
Cached: true,
|
||||
}, nil
|
||||
} else {
|
||||
@@ -135,11 +136,15 @@ func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {
|
||||
type CachedStream struct {
|
||||
io.Reader
|
||||
io.Seeker
|
||||
io.Closer
|
||||
Cached bool
|
||||
}
|
||||
|
||||
func (s *CachedStream) Seekable() bool { return s.Seeker != nil }
|
||||
func (s *CachedStream) Close() error {
|
||||
if s.Closer != nil {
|
||||
return s.Closer.Close()
|
||||
}
|
||||
if c, ok := s.Reader.(io.Closer); ok {
|
||||
return c.Close()
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -60,6 +60,7 @@ var _ = Describe("File Caches", func() {
|
||||
s, err := fc.Get(context.TODO(), &testArg{"test"})
|
||||
Expect(err).To(BeNil())
|
||||
Expect(s.Cached).To(BeFalse())
|
||||
Expect(s.Closer).To(BeNil())
|
||||
Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))
|
||||
|
||||
// Second call is a HIT
|
||||
@@ -68,6 +69,7 @@ var _ = Describe("File Caches", func() {
|
||||
Expect(err).To(BeNil())
|
||||
Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))
|
||||
Expect(s.Cached).To(BeTrue())
|
||||
Expect(s.Closer).ToNot(BeNil())
|
||||
Expect(called).To(BeFalse())
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user