@@ -268,7 +268,7 @@ func (s *SyncConfig) initialSync() error {
268268 }
269269 s .fileIndex .fileMapMutex .Unlock ()
270270
271- err = s .diffServerClient (s .WatchPath , & localChanges , fileMapClone )
271+ err = s .diffServerClient (s .WatchPath , & localChanges , fileMapClone , false )
272272 if err != nil {
273273 return errors .Trace (err )
274274 }
@@ -292,7 +292,7 @@ func (s *SyncConfig) initialSync() error {
292292 return nil
293293}
294294
295- func (s * SyncConfig ) diffServerClient (filepath string , sendChanges * []* fileInformation , downloadChanges map [string ]* fileInformation ) error {
295+ func (s * SyncConfig ) diffServerClient (filepath string , sendChanges * []* fileInformation , downloadChanges map [string ]* fileInformation , dontSend bool ) error {
296296 relativePath := getRelativeFromFullPath (filepath , s .WatchPath )
297297 stat , err := os .Lstat (filepath )
298298
@@ -319,34 +319,34 @@ func (s *SyncConfig) diffServerClient(filepath string, sendChanges *[]*fileInfor
319319 }
320320 s .fileIndex .fileMapMutex .Unlock ()
321321
322- return nil
322+ dontSend = true
323323 }
324324 }
325325
326- s .fileIndex .fileMapMutex .Lock ()
327- shouldUpload := shouldUpload (relativePath , stat , s , true )
328- s .fileIndex .fileMapMutex .Unlock ()
329-
330- if shouldUpload == false {
331- return nil
332- }
333-
334326 if stat .IsDir () {
335- return s .diffDir (filepath , stat , sendChanges , downloadChanges )
327+ return s .diffDir (filepath , stat , sendChanges , downloadChanges , dontSend )
336328 }
337329
338- // Add file to upload
339- * sendChanges = append (* sendChanges , & fileInformation {
340- Name : relativePath ,
341- Mtime : roundMtime (stat .ModTime ()),
342- Size : stat .Size (),
343- IsDirectory : false ,
344- })
330+ if dontSend == false {
331+ s .fileIndex .fileMapMutex .Lock ()
332+ shouldUpload := shouldUpload (relativePath , stat , s , true )
333+ s .fileIndex .fileMapMutex .Unlock ()
334+
335+ if shouldUpload {
336+ // Add file to upload
337+ * sendChanges = append (* sendChanges , & fileInformation {
338+ Name : relativePath ,
339+ Mtime : roundMtime (stat .ModTime ()),
340+ Size : stat .Size (),
341+ IsDirectory : false ,
342+ })
343+ }
344+ }
345345
346346 return nil
347347}
348348
349- func (s * SyncConfig ) diffDir (filepath string , stat os.FileInfo , sendChanges * []* fileInformation , downloadChanges map [string ]* fileInformation ) error {
349+ func (s * SyncConfig ) diffDir (filepath string , stat os.FileInfo , sendChanges * []* fileInformation , downloadChanges map [string ]* fileInformation , dontSend bool ) error {
350350 relativePath := getRelativeFromFullPath (filepath , s .WatchPath )
351351 files , err := ioutil .ReadDir (filepath )
352352
@@ -355,17 +355,23 @@ func (s *SyncConfig) diffDir(filepath string, stat os.FileInfo, sendChanges *[]*
355355 return nil
356356 }
357357
358- if len (files ) == 0 && relativePath != "" {
359- * sendChanges = append (* sendChanges , & fileInformation {
360- Name : relativePath ,
361- Mtime : roundMtime (stat .ModTime ()),
362- Size : stat .Size (),
363- IsDirectory : true ,
364- })
358+ if len (files ) == 0 && relativePath != "" && dontSend == false {
359+ s .fileIndex .fileMapMutex .Lock ()
360+ shouldUpload := shouldUpload (relativePath , stat , s , true )
361+ s .fileIndex .fileMapMutex .Unlock ()
362+
363+ if shouldUpload {
364+ * sendChanges = append (* sendChanges , & fileInformation {
365+ Name : relativePath ,
366+ Mtime : roundMtime (stat .ModTime ()),
367+ Size : stat .Size (),
368+ IsDirectory : true ,
369+ })
370+ }
365371 }
366372
367373 for _ , f := range files {
368- if err := s .diffServerClient (path .Join (filepath , f .Name ()), sendChanges , downloadChanges ); err != nil {
374+ if err := s .diffServerClient (path .Join (filepath , f .Name ()), sendChanges , downloadChanges , dontSend ); err != nil {
369375 return errors .Trace (err )
370376 }
371377 }
0 commit comments