| 230 | } |
| 231 | |
| 232 | func (s *Sync) startUpstream() { |
| 233 | defer s.Stop(nil) |
| 234 | s.tree = notify.NewTree() |
| 235 | |
| 236 | // Set up a watchpoint listening for events within a directory tree rooted at specified directory |
| 237 | watchPath := s.LocalPath + "/..." |
| 238 | if s.Options.NoRecursiveWatch { |
| 239 | watchPath = s.LocalPath |
| 240 | } |
| 241 | err := s.tree.Watch(watchPath, s.upstream.events, func(path string) bool { |
| 242 | if s.ignoreMatcher == nil || s.ignoreMatcher.RequireFullScan() { |
| 243 | return false |
| 244 | } |
| 245 | |
| 246 | stat, err := os.Stat(path) |
| 247 | if err != nil { |
| 248 | return false |
| 249 | } |
| 250 | |
| 251 | return s.ignoreMatcher.Matches(path[len(s.LocalPath):], stat.IsDir()) |
| 252 | }, notify.All) |
| 253 | if err != nil { |
| 254 | s.Stop(err) |
| 255 | return |
| 256 | } |
| 257 | defer s.tree.Stop(s.upstream.events) |
| 258 | if s.readyChan != nil { |
| 259 | s.readyChan <- true |
| 260 | } |
| 261 | |
| 262 | err = s.upstream.mainLoop() |
| 263 | if err != nil { |
| 264 | s.Stop(errors.Wrap(err, "upstream")) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | func (s *Sync) startDownstream() { |
| 269 | defer s.Stop(nil) |