@@ -2,7 +2,6 @@ package clip
22
33import (
44 "context"
5- "os"
65 "path"
76 "strconv"
87 "sync"
@@ -25,19 +24,14 @@ type FSNode struct {
2524 dirEntries []fuse.DirEntry
2625}
2726
28- const clipFileHandleFDCacheSize = 2048
27+ const clipFileViewFDCacheSize = 2048
2928
3029type clipFileHandle struct {
31- node * FSNode
32- mu sync.Mutex
33- files map [string ]* os.File
30+ node * FSNode
3431}
3532
3633func newClipFileHandle (node * FSNode ) * clipFileHandle {
37- return & clipFileHandle {
38- node : node ,
39- files : make (map [string ]* os.File ),
40- }
34+ return & clipFileHandle {node : node }
4135}
4236
4337func (fh * clipFileHandle ) Read (ctx context.Context , dest []byte , off int64 ) (fuse.ReadResult , syscall.Errno ) {
@@ -57,33 +51,7 @@ func (fh *clipFileHandle) Read(ctx context.Context, dest []byte, off int64) (fus
5751}
5852
5953func (fh * clipFileHandle ) Release (ctx context.Context ) syscall.Errno {
60- fh .mu .Lock ()
61- defer fh .mu .Unlock ()
62- var firstErr syscall.Errno
63- for path , file := range fh .files {
64- if err := file .Close (); err != nil && firstErr == fs .OK {
65- firstErr = fs .ToErrno (err )
66- }
67- delete (fh .files , path )
68- }
69- return firstErr
70- }
71-
72- func (fh * clipFileHandle ) openViewFile (path string ) (* os.File , error ) {
73- fh .mu .Lock ()
74- defer fh .mu .Unlock ()
75- if file := fh .files [path ]; file != nil {
76- return file , nil
77- }
78- if len (fh .files ) >= clipFileHandleFDCacheSize {
79- return nil , syscall .EMFILE
80- }
81- file , err := os .Open (path )
82- if err != nil {
83- return nil , err
84- }
85- fh .files [path ] = file
86- return file , nil
54+ return fs .OK
8755}
8856
8957func (fh * clipFileHandle ) readClientLocalFileView (ctx context.Context , dest []byte , off int64 ) (fuse.ReadResult , bool , syscall.Errno ) {
@@ -119,7 +87,7 @@ func (fh *clipFileHandle) readClientLocalFileView(ctx context.Context, dest []by
11987 return nil , false , fs .OK
12088 }
12189
122- file , err := fh .openViewFile (view .Path )
90+ file , err := fh .node . filesystem . openViewFile (view .Path )
12391 if err != nil {
12492 if traceRead {
12593 fh .node .observeRead (ctx , fh .node .clientLocalFileViewReadTrace (view , off , readLen , 0 , started , err ))
0 commit comments