Add missing watch event for files
If a file was supposed to exist in a directory, and it didn't exist yet, when it gets created, we should notice, and cause an event so that we wake up and actually see about then creating that file!
This commit is contained in:
4
file.go
4
file.go
@@ -176,6 +176,10 @@ func (obj FileType) Watch(v *Vertex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if delta_depth < 0 {
|
if delta_depth < 0 {
|
||||||
|
log.Println("Parent!")
|
||||||
|
if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir
|
||||||
|
send = true
|
||||||
|
}
|
||||||
watcher.Remove(current)
|
watcher.Remove(current)
|
||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
|
|||||||
11
misc.go
11
misc.go
@@ -52,6 +52,17 @@ func HasPathPrefix(p, prefix string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delta of path prefix, tells you how many path tokens different the prefix is
|
||||||
|
func PathPrefixDelta(p, prefix string) int {
|
||||||
|
|
||||||
|
if !HasPathPrefix(p, prefix) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
patharray := PathSplit(p)
|
||||||
|
prefixarray := PathSplit(prefix)
|
||||||
|
return len(patharray) - len(prefixarray)
|
||||||
|
}
|
||||||
|
|
||||||
func PathIsDir(p string) bool {
|
func PathIsDir(p string) bool {
|
||||||
return p[len(p)-1:] == "/" // a dir has a trailing slash in this context
|
return p[len(p)-1:] == "/" // a dir has a trailing slash in this context
|
||||||
}
|
}
|
||||||
|
|||||||
36
misc_test.go
36
misc_test.go
@@ -82,6 +82,41 @@ func TestMiscT3(t *testing.T) {
|
|||||||
|
|
||||||
func TestMiscT4(t *testing.T) {
|
func TestMiscT4(t *testing.T) {
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz", "/foo/ba") != -1 {
|
||||||
|
t.Errorf("Result should be -1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz", "/foo/bar") != 1 {
|
||||||
|
t.Errorf("Result should be 1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz", "/foo/bar/") != 1 {
|
||||||
|
t.Errorf("Result should be 1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz/", "/foo/bar") != 1 {
|
||||||
|
t.Errorf("Result should be 1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz/", "/foo/bar/") != 1 {
|
||||||
|
t.Errorf("Result should be 1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz/", "/foo/bar/baz/dude") != -1 {
|
||||||
|
t.Errorf("Result should be -1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz/a/b/c/", "/foo/bar/baz") != 3 {
|
||||||
|
t.Errorf("Result should be 3.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if PathPrefixDelta("/foo/bar/baz/", "/foo/bar/baz") != 0 {
|
||||||
|
t.Errorf("Result should be 0.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMiscT5(t *testing.T) {
|
||||||
|
|
||||||
if PathIsDir("/foo/bar/baz/") != true {
|
if PathIsDir("/foo/bar/baz/") != true {
|
||||||
t.Errorf("Result should be false.")
|
t.Errorf("Result should be false.")
|
||||||
}
|
}
|
||||||
@@ -97,5 +132,4 @@ func TestMiscT4(t *testing.T) {
|
|||||||
if PathIsDir("/") != true {
|
if PathIsDir("/") != true {
|
||||||
t.Errorf("Result should be true.")
|
t.Errorf("Result should be true.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user