From 750fbbb8fec3a0c2ca70e8534218fa68771219cb Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Mon, 24 Jan 2022 13:25:55 +0000 Subject: [PATCH] Delete cache when dir mismatch (fixes #265) --- src/library/library.cr | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/library/library.cr b/src/library/library.cr index a2dc28d..bd801ac 100644 --- a/src/library/library.cr +++ b/src/library/library.cr @@ -24,7 +24,21 @@ class Library begin Compress::Gzip::Reader.open path do |content| - @@default = Library.from_yaml content + loaded = Library.from_yaml content + if loaded.dir != Config.current.library_path + # We will have to do a full restart in this case. Otherwise having + # two instances of the library will cause some weirdness. + Logger.fatal "Cached library dir #{loaded.dir} does not match " \ + "current library dir #{Config.current.library_path}. " \ + "Deleting cache" + File.delete path + Logger.fatal "Invalid library cache deleted. Mango needs to " \ + "perform a full reset to recover from this. " \ + "Pleae restart Mango." + Logger.fatal "Exiting" + exit 1 + end + @@default = loaded end Library.default.register_jobs rescue e