Revert "Try clearing the cache iff the summary pickle doesn't load."

This reverts commit a04c19c760.

- This caused problems when the api of the pickled objects changed.
This commit is contained in:
Andrew Hamilton 2017-08-28 16:23:05 +01:00
parent 5a26b9fd13
commit e63dd40320
2 changed files with 18 additions and 9 deletions

View file

@ -219,12 +219,13 @@ class MainTestCase(unittest.TestCase):
# tmp_total = _tmp_total()
foo_path = os.path.join(root_path, "foo")
open(foo_path, "w").close()
__main__.manage_cache(root_path)
with __main__.chdir(root_path):
with contextlib.redirect_stdout(io.StringIO()):
__main__.main(root_path, loop, worker_count=2,
is_being_tested=True)
for file_name in ["summary.pickle", "log", "foo-metadata",
"foo-contents"]:
for file_name in ["summary.pickle", "creation_time", "log",
"foo-metadata", "foo-contents"]:
self.assertTrue(os.path.exists(".vigil/" + file_name))
self.assertEqual(_mount_total(), mount_total)
# self.assertEqual(_tmp_total(), tmp_total)

View file

@ -930,13 +930,7 @@ def load_state(pickle_path, jobs_added_event, appearance_changed_event,
try:
with gzip.open(pickle_path, "rb") as file_:
screen = pickle.load(file_)
except (FileNotFoundError, AttributeError):
cache_path = os.path.join(root_path, tools.CACHE_PATH)
if os.path.exists(cache_path):
print("Vigil has been updated, so clearing the cache and"
" recalculating all results...")
shutil.rmtree(cache_path, ignore_errors=True)
os.mkdir(cache_path)
except FileNotFoundError:
summary = Summary(root_path, jobs_added_event)
log = Log(appearance_changed_event)
screen = Screen(summary, log, appearance_changed_event, loop)
@ -1013,6 +1007,19 @@ def chdir(path):
os.chdir(old_cwd)
def manage_cache(root_path):
cache_path = os.path.join(root_path, tools.CACHE_PATH)
timestamp_path = os.path.join(cache_path, "creation_time")
if os.path.exists(cache_path) and \
os.stat(__file__).st_mtime > os.stat(timestamp_path).st_mtime:
print("Vigil has been updated, so clearing the cache and"
" recalculating all results...")
shutil.rmtree(cache_path)
if not os.path.exists(cache_path):
os.mkdir(cache_path)
open(timestamp_path, "w").close()
def check_arguments():
cmdline_help = __doc__ + USAGE.replace("*", "")
arguments = docopt.docopt(cmdline_help, help=False)
@ -1049,6 +1056,7 @@ def check_arguments():
def entry_point():
root_path, worker_count, editor_command, theme = check_arguments()
with terminal.console_title("vigil: " + os.path.basename(root_path)):
manage_cache(root_path)
with chdir(root_path): # FIX: Don't change directory if possible.
loop = asyncio.get_event_loop()
main(root_path, loop, worker_count, editor_command, theme)