Fixed bug that caused vigil not to restart if the root directory was renamed.

This commit is contained in:
Andrew Hamilton 2016-01-26 14:44:42 +00:00
parent 61efffa0b7
commit 17516cd831
3 changed files with 28 additions and 18 deletions

4
BUGS
View file

@ -3,8 +3,6 @@ Current
e.g. vigil.py pylint, BUGS metadata, BUGS _pygments
- Scrolling in the help screen doesn't work with the arrow keys.
- Within the sandbox sudo is not working for tools.
- The cache is not relocatable anymore. i.e. Restarting vigil after renaming
the project directory is failing.
Current (tool related)
@ -209,6 +207,8 @@ Fixed
- There is an exception if vigil's window is made too small.
<- When the window is narrower than 10 or shorter than 20 the contents
start to crop instead of shrink.
- The cache is not relocatable anymore. i.e. Restarting vigil after renaming
the project directory is failing.
Won't fix

14
vigil
View file

@ -872,7 +872,9 @@ def add_watch_manager_to_mainloop(root_path, mainloop, on_filesystem_change,
notifier.read_events()
notifier.process_events()
on_filesystem_change()
mainloop.add_reader(watch_manager.get_fd(), on_inotify)
watch_manager_fd = watch_manager.get_fd()
mainloop.add_reader(watch_manager_fd, on_inotify)
return watch_manager_fd
_UPDATE_THREAD_STOPPED = False
@ -906,18 +908,19 @@ def main(root_path, is_being_tested=False):
summary = screen._summary
summary._lock = threading.Lock()
summary._jobs_added_event = jobs_added_event
summary._root_path = root_path
log = screen._log
log._appearance_changed_event = appearance_changed_event
summary.sync_with_filesystem()
log.log_message("Program started.")
jobs_added_event.set()
def on_filesystem_change():
log.log_message("Filesystem changed.")
summary.sync_with_filesystem()
appearance_changed_event.set()
add_watch_manager_to_mainloop(root_path, loop, on_filesystem_change,
is_path_excluded)
log.log_message("Program started.")
jobs_added_event.set()
watch_manager_fd = add_watch_manager_to_mainloop(
root_path, loop, on_filesystem_change, is_path_excluded)
runners = []
sandbox_temp_dir = tempfile.mkdtemp()
sandbox = sandbox_fs.SandboxFs(sandbox_temp_dir)
@ -973,6 +976,7 @@ def main(root_path, is_being_tested=False):
finally:
sandbox.umount()
os.rmdir(sandbox_temp_dir)
loop.remove_reader(watch_manager_fd)
@contextlib.contextmanager

View file

@ -234,23 +234,29 @@ def _tmp_total():
class MainTestCase(unittest.TestCase):
def test_start_and_run_a_job_then_stop_with_no_leaks(self):
temp_dir = tempfile.mkdtemp()
try:
def test_main_and_restart_and_no_leaks_and_is_relocatable(self):
def test_run(root_path):
mount_total = _mount_total()
tmp_total = _tmp_total()
foo_path = os.path.join(temp_dir, "foo")
foo_path = os.path.join(root_path, "foo")
open(foo_path, "w").close()
vigil.manage_cache(temp_dir)
with vigil.chdir(temp_dir):
vigil.manage_cache(root_path)
with vigil.chdir(root_path):
with contextlib.redirect_stdout(io.StringIO()):
vigil.main(temp_dir, is_being_tested=True)
self.assertTrue(os.path.exists(".vigil/.summary.pickle"))
self.assertTrue(os.path.exists(".vigil/.creation-time"))
self.assertTrue(os.path.exists(".vigil/.log"))
self.assertTrue(os.path.exists(".vigil/foo-metadata"))
vigil.main(root_path, is_being_tested=True)
for file_name in [".summary.pickle", ".creation-time", ".log",
"foo-metadata"]:
self.assertTrue(os.path.exists(".vigil/" + file_name))
self.assertEqual(_mount_total(), mount_total)
self.assertEqual(_tmp_total(), tmp_total)
temp_dir = tempfile.mkdtemp()
try:
first_dir = os.path.join(temp_dir, "first")
os.mkdir(first_dir)
test_run(first_dir)
second_dir = os.path.join(temp_dir, "second")
os.rename(first_dir, second_dir)
test_run(second_dir)
finally:
shutil.rmtree(temp_dir)