@@ -31,10 +31,11 @@ const rescanPeriod = time.Minute * 15
3131
3232// DownstreamOptions holds the options for the downstream server
3333type DownstreamOptions struct {
34- RemotePath string
35- ExcludePaths []string
36- ExitOnClose bool
37- Throttle int64
34+ RemotePath string
35+ ExcludePaths []string
36+ ExitOnClose bool
37+ NoRecursiveWatch bool
38+ Throttle int64
3839
3940 Polling bool
4041 Ping bool
@@ -78,7 +79,12 @@ func StartDownstreamServer(reader io.Reader, writer io.Writer, options *Downstre
7879
7980 go func () {
8081 // set up a watchpoint listening for events within a directory tree rooted at specified directory
81- err := notify .WatchWithFilter (options .RemotePath + "/..." , downStream .events , func (s string ) bool {
82+ watchPath := options .RemotePath + "/..."
83+ if options .NoRecursiveWatch {
84+ watchPath = options .RemotePath
85+ }
86+
87+ err := notify .WatchWithFilter (watchPath , downStream .events , func (s string ) bool {
8288 if ignoreMatcher == nil || ignoreMatcher .RequireFullScan () {
8389 return false
8490 }
@@ -229,7 +235,7 @@ func (d *Downstream) ChangesCount(context.Context, *remote.Empty) (*remote.Chang
229235
230236 // Walk through the dir
231237 if d .options .Polling {
232- walkDir (d .options .RemotePath , d .options .RemotePath , d .ignoreMatcher , newState , throttle )
238+ walkDir (d .options .RemotePath , d .options .RemotePath , d .ignoreMatcher , newState , d . options . NoRecursiveWatch , throttle )
233239 }
234240
235241 changeAmount := int64 (0 )
@@ -272,7 +278,7 @@ func (d *Downstream) getWatchState() map[string]*remote.Change {
272278 d .lastRescan = & now
273279
274280 newState := make (map [string ]* remote.Change )
275- walkDir (d .options .RemotePath , d .options .RemotePath , d .ignoreMatcher , newState , 0 )
281+ walkDir (d .options .RemotePath , d .options .RemotePath , d .ignoreMatcher , newState , d . options . NoRecursiveWatch , 0 )
276282 return newState
277283 } else if changeAmount == 0 {
278284 return nil
@@ -305,7 +311,7 @@ func (d *Downstream) Changes(empty *remote.Empty, stream remote.Downstream_Chang
305311 if ! d .options .Polling {
306312 newState = d .getWatchState ()
307313 } else {
308- walkDir (d .options .RemotePath , d .options .RemotePath , d .ignoreMatcher , newState , throttle )
314+ walkDir (d .options .RemotePath , d .options .RemotePath , d .ignoreMatcher , newState , d . options . NoRecursiveWatch , throttle )
309315 }
310316
311317 if newState != nil {
@@ -384,7 +390,7 @@ func (d *Downstream) applyChange(newState map[string]*remote.Change, fullPath st
384390 }
385391 }
386392
387- walkDir (d .options .RemotePath , fullPath , d .ignoreMatcher , newState , time .Duration (d .options .Throttle )* time .Millisecond )
393+ walkDir (d .options .RemotePath , fullPath , d .ignoreMatcher , newState , d . options . NoRecursiveWatch , time .Duration (d .options .Throttle )* time .Millisecond )
388394 } else {
389395 if d .ignoreMatcher == nil || ! d .ignoreMatcher .RequireFullScan () || ! d .ignoreMatcher .Matches (relativePath , false ) {
390396 newState [fullPath ] = & remote.Change {
@@ -525,7 +531,7 @@ func streamChanges(basePath string, oldState map[string]*remote.Change, newState
525531 return changeAmount , nil
526532}
527533
528- func walkDir (basePath string , path string , ignoreMatcher ignoreparser.IgnoreParser , state map [string ]* remote.Change , throttle time.Duration ) {
534+ func walkDir (basePath string , path string , ignoreMatcher ignoreparser.IgnoreParser , state map [string ]* remote.Change , noRecursive bool , throttle time.Duration ) {
529535 files , err := ioutil .ReadDir (path )
530536 if err != nil {
531537 // We ignore errors here
@@ -566,7 +572,9 @@ func walkDir(basePath string, path string, ignoreMatcher ignoreparser.IgnorePars
566572 }
567573 }
568574
569- walkDir (basePath , absolutePath , ignoreMatcher , state , throttle )
575+ if ! noRecursive {
576+ walkDir (basePath , absolutePath , ignoreMatcher , state , noRecursive , throttle )
577+ }
570578 } else {
571579 // Check if not ignored
572580 if ignoreMatcher == nil || ! ignoreMatcher .RequireFullScan () || ! ignoreMatcher .Matches (absolutePath [len (basePath ):], false ) {
0 commit comments