@@ -82,11 +82,11 @@ func (w *LocalWatcher) Start() error {
8282 w .ticker = time .NewTicker (w .pollingTime )
8383 go func () {
8484 // launch synchronization also the first time
85- w .sync ()
85+ w .sync (true )
8686 for {
8787 select {
8888 case <- w .ticker .C :
89- w .sync ()
89+ w .sync (false )
9090
9191 case <- w .stop :
9292 close (w .Events )
@@ -203,7 +203,7 @@ func (w *LocalWatcher) Close() {
203203 w .stop <- true
204204}
205205
206- func (w * LocalWatcher ) sync () {
206+ func (w * LocalWatcher ) sync (firstSync bool ) {
207207 // allow only one sync at same time
208208 if ! atomic .CompareAndSwapUint32 (& w .syncing , 0 , 1 ) {
209209 return
@@ -233,57 +233,61 @@ func (w *LocalWatcher) sync() {
233233 FileMode : fi .Mode (),
234234 }
235235
236- fileList [walkPath ] = obj
237-
238- // Check if the object is cached by Key
239- cached := w .getCachedObject (obj )
240- // Object has been cached previously by Key
241- if cached != nil {
242- // Check if the LastModified has been changed
243- if ! cached .LastModified .Equal (obj .LastModified ) || (cached .Size != obj .Size ) {
244- event := Event {
245- Key : obj .Key ,
246- Type : FileChanged ,
247- Object : obj ,
236+ if firstSync {
237+ fileList [walkPath ] = obj
238+
239+ // Check if the object is cached by Key
240+ cached := w .getCachedObject (obj )
241+ // Object has been cached previously by Key
242+ if cached != nil {
243+ // Check if the LastModified has been changed
244+ if ! cached .LastModified .Equal (obj .LastModified ) || (cached .Size != obj .Size ) {
245+ event := Event {
246+ Key : obj .Key ,
247+ Type : FileChanged ,
248+ Object : obj ,
249+ }
250+ w .Events <- event
248251 }
249- w .Events <- event
250- }
251- // Check if the file modes have been updated
252- if cached .FileMode != obj .FileMode {
252+ // Check if the file modes have been updated
253+ if cached .FileMode != obj .FileMode {
254+ event := Event {
255+ Key : obj .Key ,
256+ Type : TagsChanged ,
257+ Object : obj ,
258+ }
259+ w .Events <- event
260+ }
261+ } else {
253262 event := Event {
254263 Key : obj .Key ,
255- Type : TagsChanged ,
264+ Type : FileCreated ,
256265 Object : obj ,
257266 }
258267 w .Events <- event
259268 }
260- } else {
261- event := Event {
262- Key : obj .Key ,
263- Type : FileCreated ,
264- Object : obj ,
265- }
266- w .Events <- event
267269 }
268- w .cache [obj .Key ] = obj
269270
271+ w .cache [obj .Key ] = obj
270272 return nil
271273 })
272274 if err != nil {
273275 w .Errors <- err
274276 return
275277 }
276278
277- for k , o := range w .cache {
278- if _ , found := fileList [k ]; ! found {
279- // file not found in the list...deleting it
280- delete (w .cache , k )
281- event := Event {
282- Key : o .Key ,
283- Type : FileDeleted ,
284- Object : o ,
279+ if len (fileList ) != 0 {
280+ for k , o := range w .cache {
281+ if _ , found := fileList [k ]; ! found {
282+ // file not found in the list...deleting it
283+ delete (w .cache , k )
284+ event := Event {
285+ Key : o .Key ,
286+ Type : FileDeleted ,
287+ Object : o ,
288+ }
289+ w .Events <- event
285290 }
286- w .Events <- event
287291 }
288292 }
289293}
0 commit comments