mirror of
				https://github.com/docker/compose.git
				synced 2025-11-03 21:25:21 +01:00 
			
		
		
		
	watch: fix more data races on darwin (#166)
This commit is contained in:
		
							parent
							
								
									4562b0bf95
								
							
						
					
					
						commit
						a6701652d2
					
				@ -21,9 +21,9 @@ type darwinNotify struct {
 | 
				
			|||||||
	// change.
 | 
						// change.
 | 
				
			||||||
	sm *sync.Mutex
 | 
						sm *sync.Mutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// ignore the first event that says the watched directory
 | 
						// When a watch is created for a directory, we've seen fsevents non-determistically
 | 
				
			||||||
	// has been created. these are fired spuriously on initiation.
 | 
						// fire 0-2 CREATE events for that directory. We want to ignore these.
 | 
				
			||||||
	ignoreCreatedEvents map[string]bool
 | 
						ignoreCreatedEvents map[string]int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *darwinNotify) loop() {
 | 
					func (d *darwinNotify) loop() {
 | 
				
			||||||
@ -41,9 +41,10 @@ func (d *darwinNotify) loop() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				if e.Flags&fsevents.ItemCreated == fsevents.ItemCreated {
 | 
									if e.Flags&fsevents.ItemCreated == fsevents.ItemCreated {
 | 
				
			||||||
					d.sm.Lock()
 | 
										d.sm.Lock()
 | 
				
			||||||
					shouldIgnore := d.ignoreCreatedEvents[e.Path]
 | 
										ignoreCount := d.ignoreCreatedEvents[e.Path]
 | 
				
			||||||
 | 
										shouldIgnore := ignoreCount > 0
 | 
				
			||||||
					if shouldIgnore {
 | 
										if shouldIgnore {
 | 
				
			||||||
						d.ignoreCreatedEvents[e.Path] = false
 | 
											d.ignoreCreatedEvents[e.Path]--
 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						// If we got a created event for something
 | 
											// If we got a created event for something
 | 
				
			||||||
						// that's not on the ignore list, we assume
 | 
											// that's not on the ignore list, we assume
 | 
				
			||||||
@ -83,13 +84,13 @@ func (d *darwinNotify) Add(name string) error {
 | 
				
			|||||||
	es.Paths = append(es.Paths, name)
 | 
						es.Paths = append(es.Paths, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if d.ignoreCreatedEvents == nil {
 | 
						if d.ignoreCreatedEvents == nil {
 | 
				
			||||||
		d.ignoreCreatedEvents = make(map[string]bool, 1)
 | 
							d.ignoreCreatedEvents = make(map[string]int, 1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	d.ignoreCreatedEvents[name] = true
 | 
						d.ignoreCreatedEvents[name] = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(es.Paths) == 1 {
 | 
						if len(es.Paths) == 1 {
 | 
				
			||||||
		go d.loop()
 | 
					 | 
				
			||||||
		es.Start()
 | 
							es.Start()
 | 
				
			||||||
 | 
							go d.loop()
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		es.Restart()
 | 
							es.Restart()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user