@@ -114,19 +114,19 @@ func (event *event) Process(fileBefore *File, reader *lineReader, abspath string
114114 )
115115 logger .Debug ("File system watcher received %v.\n " , event .String ())
116116
117- // WRITE or TRUNCATE
118- if file != nil && norm (event .Name ) == norm (abspath ) && event .Mask & winfsnotify .FS_MODIFY == winfsnotify .FS_MODIFY {
119- truncated , err = file .CheckTruncated ()
117+ // MOVED_FROM or DELETE
118+ if file != nil && norm (event .Name ) == norm (abspath ) && (event .Mask & winfsnotify .FS_MOVED_FROM == winfsnotify .FS_MOVED_FROM || event .Mask & winfsnotify .FS_DELETE == winfsnotify .FS_DELETE ) {
119+ file = nil
120+ reader .Clear ()
121+ }
122+
123+ // MOVED_TO or CREATE
124+ if file == nil && norm (event .Name ) == norm (abspath ) && (event .Mask & winfsnotify .FS_MOVED_TO == winfsnotify .FS_MOVED_TO || event .Mask & winfsnotify .FS_CREATE == winfsnotify .FS_CREATE ) {
125+ file , err = open (abspath )
120126 if err != nil {
121127 return
122128 }
123- if truncated {
124- _ , err = file .Seek (0 , io .SeekStart )
125- if err != nil {
126- return
127- }
128- reader .Clear ()
129- }
129+ reader .Clear ()
130130 for {
131131 line , eof , err = reader .ReadLine (file )
132132 if err != nil {
@@ -139,19 +139,19 @@ func (event *event) Process(fileBefore *File, reader *lineReader, abspath string
139139 }
140140 }
141141
142- // MOVED_FROM or DELETE
143- if file != nil && norm (event .Name ) == norm (abspath ) && (event .Mask & winfsnotify .FS_MOVED_FROM == winfsnotify .FS_MOVED_FROM || event .Mask & winfsnotify .FS_DELETE == winfsnotify .FS_DELETE ) {
144- file = nil
145- reader .Clear ()
146- }
147-
148- // MOVED_TO or CREATE
149- if file == nil && norm (event .Name ) == norm (abspath ) && (event .Mask & winfsnotify .FS_MOVED_TO == winfsnotify .FS_MOVED_TO || event .Mask & winfsnotify .FS_CREATE == winfsnotify .FS_CREATE ) {
150- file , err = open (abspath )
142+ // WRITE or TRUNCATE
143+ if file != nil && norm (event .Name ) == norm (abspath ) && event .Mask & winfsnotify .FS_MODIFY == winfsnotify .FS_MODIFY {
144+ truncated , err = file .CheckTruncated ()
151145 if err != nil {
152146 return
153147 }
154- reader .Clear ()
148+ if truncated {
149+ _ , err = file .Seek (0 , io .SeekStart )
150+ if err != nil {
151+ return
152+ }
153+ reader .Clear ()
154+ }
155155 for {
156156 line , eof , err = reader .ReadLine (file )
157157 if err != nil {
@@ -163,6 +163,7 @@ func (event *event) Process(fileBefore *File, reader *lineReader, abspath string
163163 lines = append (lines , line )
164164 }
165165 }
166+
166167 return
167168}
168169
0 commit comments