From d0cd6cd456813a439479d6281a003c148c43c8f8 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 24 Mar 2021 10:33:05 +0100 Subject: [PATCH] make leveldb handling more resilient --- Main.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index 64df6ff..62eee1f 100644 --- a/Main.hs +++ b/Main.hs @@ -192,8 +192,11 @@ deleteLocalStorage = do whitelist <- asks whitelist let path = webengine "Local Storage" "leveldb" + dbIsOk <- liftIO $ D.doesFileExist (path "LOCK") + when (not dbIsOk) (throwError "Database is missing or corrupted") + version <- withDB path (\db -> L.get db def "VERSION") - when (version /= Just "1") (throwError "Unsupported schema version") + when (version /= Just "1") (throwError "Database is empty or the schema unsupported") withDB path $ \db -> do badDomains <- L.withIterator db def $ \i -> @@ -234,8 +237,11 @@ deleteSessionStorage = do whitelist <- asks whitelist let path = webengine "Session Storage" + dbIsOk <- liftIO $ D.doesFileExist (path "LOCK") + when (not dbIsOk) (throwError "Database is missing or corrupted") + version <- withDB path (\db -> L.get db def "version") - when (version /= Just "1") (throwError "Unsupported schema version") + when (version /= Just "1") (throwError "Database is empty or the schema unsupported") withDB path $ \db -> do -- map of id -> isBad