mirror of
https://github.com/docker/compose.git
synced 2025-07-26 23:24:05 +02:00
watch: fix a spurious error (#344)
This commit is contained in:
parent
c8a358a455
commit
c5bce8bd42
@ -277,6 +277,32 @@ func TestWriteGoodLink(t *testing.T) {
|
|||||||
f.assertEvents(goodFile, link)
|
f.assertEvents(goodFile, link)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWatchBrokenLink(t *testing.T) {
|
||||||
|
f := newNotifyFixture(t)
|
||||||
|
defer f.tearDown()
|
||||||
|
|
||||||
|
newRoot, err := NewDir(t.Name())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer newRoot.TearDown()
|
||||||
|
|
||||||
|
link := filepath.Join(newRoot.Path(), "brokenLink")
|
||||||
|
missingFile := filepath.Join(newRoot.Path(), "missingFile")
|
||||||
|
err = os.Symlink(missingFile, link)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = f.notify.Add(newRoot.Path())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Remove(link)
|
||||||
|
f.assertEvents(link)
|
||||||
|
}
|
||||||
|
|
||||||
type notifyFixture struct {
|
type notifyFixture struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
root *TempDir
|
root *TempDir
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package watch
|
package watch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -28,26 +29,27 @@ type linuxNotify struct {
|
|||||||
func (d *linuxNotify) Add(name string) error {
|
func (d *linuxNotify) Add(name string) error {
|
||||||
fi, err := os.Stat(name)
|
fi, err := os.Stat(name)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return fmt.Errorf("notify.Add(%q): %v", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's a file that doesn't exist watch it's parent
|
// if it's a file that doesn't exist watch it's parent
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
parent := filepath.Join(name, "..")
|
parent := filepath.Join(name, "..")
|
||||||
err = d.watcher.Add(parent)
|
err = d.watcher.Add(parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("notify.Add(%q): %v", name, err)
|
||||||
}
|
}
|
||||||
d.watchList[parent] = true
|
d.watchList[parent] = true
|
||||||
} else if fi.IsDir() {
|
} else if fi.IsDir() {
|
||||||
err = d.watchRecursively(name)
|
err = d.watchRecursively(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("notify.Add(%q): %v", name, err)
|
||||||
}
|
}
|
||||||
d.watchList[name] = true
|
d.watchList[name] = true
|
||||||
} else {
|
} else {
|
||||||
err = d.watcher.Add(name)
|
err = d.watcher.Add(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("notify.Add(%q): %v", name, err)
|
||||||
}
|
}
|
||||||
d.watchList[name] = true
|
d.watchList[name] = true
|
||||||
}
|
}
|
||||||
@ -61,7 +63,14 @@ func (d *linuxNotify) watchRecursively(dir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return d.watcher.Add(path)
|
err = d.watcher.Add(path)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("watcher.Add(%q): %v", path, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user