recwatch: Remove watcher on file move
Fix #120 Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
@@ -247,6 +247,13 @@ func (obj *RecWatcher) Watch() error {
|
|||||||
index--
|
index--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when the file is moved, remove the watcher and add a new one,
|
||||||
|
// so we stop tracking the old inode.
|
||||||
|
if deltaDepth >= 0 && (event.Op&fsnotify.Rename == fsnotify.Rename) {
|
||||||
|
obj.watcher.Remove(current)
|
||||||
|
obj.watcher.Add(current)
|
||||||
|
}
|
||||||
|
|
||||||
// we must be a parent watcher, so descend in
|
// we must be a parent watcher, so descend in
|
||||||
if deltaDepth < 0 {
|
if deltaDepth < 0 {
|
||||||
// XXX: we can block here due to: https://github.com/fsnotify/fsnotify/issues/123
|
// XXX: we can block here due to: https://github.com/fsnotify/fsnotify/issues/123
|
||||||
|
|||||||
40
test/shell/file-move.sh
Executable file
40
test/shell/file-move.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
mkdir -p /tmp/mgmt/
|
||||||
|
rm /tmp/mgmt/f1 || true
|
||||||
|
|
||||||
|
# run empty graph, with prometheus support
|
||||||
|
timeout --kill-after=20s 15s ./mgmt run --tmp-prefix --yaml=file-move.yaml 2>&1 | tee /tmp/mgmt/file-move.log &
|
||||||
|
pid=$!
|
||||||
|
sleep 5s # let it converge
|
||||||
|
|
||||||
|
initial=$(grep -c 'File\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log)
|
||||||
|
|
||||||
|
mv /tmp/mgmt/f1 /tmp/mgmt/f2
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
after_move_count=$(grep -c 'File\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log)
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
echo f2 > /tmp/mgmt/f2
|
||||||
|
|
||||||
|
after_moved_file_count=$(grep -c 'File\[file1\]: contentCheckApply(true)' /tmp/mgmt/file-move.log)
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ${after_move_count} -le ${initial} ]]
|
||||||
|
then
|
||||||
|
echo File move did not trigger a CheckApply
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${after_moved_file_count} -gt ${after_move_count} ]]
|
||||||
|
then
|
||||||
|
echo Changing the moved file did trigger a CheckApply
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
killall -SIGINT mgmt # send ^C to exit mgmt
|
||||||
|
wait $pid # get exit status
|
||||||
|
exit $?
|
||||||
9
test/shell/file-move.yaml
Normal file
9
test/shell/file-move.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
graph: mygraph
|
||||||
|
resources:
|
||||||
|
file:
|
||||||
|
- name: file1
|
||||||
|
path: "/tmp/mgmt/f1"
|
||||||
|
content: |
|
||||||
|
i am f1
|
||||||
|
state: exists
|
||||||
Reference in New Issue
Block a user