make leveldb handling more resilient

master
Michele Guerini Rocco 2021-03-24 10:33:05 +01:00
parent 0ab048b795
commit d0cd6cd456
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
1 changed files with 8 additions and 2 deletions

10
Main.hs
View File

@ -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