fix some warnings
This commit is contained in:
parent
05e930a0a5
commit
6f371de3aa
50
Main.hs
50
Main.hs
@ -7,8 +7,9 @@
|
|||||||
{-# LANGUAGE MultiWayIf #-}
|
{-# LANGUAGE MultiWayIf #-}
|
||||||
|
|
||||||
-- Databases
|
-- Databases
|
||||||
import Database.Selda (Text, liftIO, (!))
|
import Database.Selda (Text, liftIO, (!))
|
||||||
import Database.Selda.SQLite (withSQLite)
|
import Database.Selda.SQLite (withSQLite)
|
||||||
|
import Control.Monad.Trans.Resource (ResourceT)
|
||||||
import qualified Database.Selda as S
|
import qualified Database.Selda as S
|
||||||
import qualified Database.LevelDB as L
|
import qualified Database.LevelDB as L
|
||||||
import qualified Database.LevelDB.Streaming as LS
|
import qualified Database.LevelDB.Streaming as LS
|
||||||
@ -200,18 +201,13 @@ deleteCookies :: Action Result
|
|||||||
deleteCookies = do
|
deleteCookies = do
|
||||||
dir <- asks webenginePath
|
dir <- asks webenginePath
|
||||||
dry <- asks (dryRun . options)
|
dry <- asks (dryRun . options)
|
||||||
unsafe <- asks (unsafe . options)
|
|
||||||
|
|
||||||
let
|
-- check for database
|
||||||
database = dir </> "Cookies"
|
exists <- liftIO $ D.doesFileExist (dir </> "Cookies")
|
||||||
context = if unsafe then bypassLocks "Cookies"
|
|
||||||
else ($ database)
|
|
||||||
|
|
||||||
exists <- liftIO $ D.doesFileExist database
|
|
||||||
when (not exists) (throwError "database is missing")
|
when (not exists) (throwError "database is missing")
|
||||||
|
|
||||||
whitelist <- map S.text <$> asks whitelist
|
whitelist <- map S.text <$> asks whitelist
|
||||||
context $ \database -> do
|
withoutLocks "Cookies" $ \database -> do
|
||||||
CE.handle dbErrors $ withSQLite database $ do
|
CE.handle dbErrors $ withSQLite database $ do
|
||||||
bad <- S.query $ do
|
bad <- S.query $ do
|
||||||
cookie <- S.select cookies
|
cookie <- S.select cookies
|
||||||
@ -229,18 +225,13 @@ deleteQuotaOrigins :: Action Result
|
|||||||
deleteQuotaOrigins = do
|
deleteQuotaOrigins = do
|
||||||
dir <- asks webenginePath
|
dir <- asks webenginePath
|
||||||
dry <- asks (dryRun . options)
|
dry <- asks (dryRun . options)
|
||||||
unsafe <- asks (unsafe . options)
|
|
||||||
|
|
||||||
let
|
-- check for database
|
||||||
database = dir </> "QuotaManager"
|
exists <- liftIO $ D.doesFileExist (dir </> "QuotaManager")
|
||||||
context = if unsafe then bypassLocks "QuotaManager"
|
|
||||||
else ($ database)
|
|
||||||
|
|
||||||
exists <- liftIO $ D.doesFileExist database
|
|
||||||
when (not exists) (throwError "database is missing")
|
when (not exists) (throwError "database is missing")
|
||||||
|
|
||||||
whitelist <- map pattern <$> asks whitelist
|
whitelist <- map mkPattern <$> asks whitelist
|
||||||
context $ \database -> do
|
withoutLocks "QuotaManager" $ \database -> do
|
||||||
CE.handle dbErrors $ withSQLite database $ do
|
CE.handle dbErrors $ withSQLite database $ do
|
||||||
bad <- S.query $ do
|
bad <- S.query $ do
|
||||||
quota <- S.select quotaOrigins
|
quota <- S.select quotaOrigins
|
||||||
@ -259,7 +250,7 @@ deleteQuotaOrigins = do
|
|||||||
S.restrict (url `S.like` S.the pattern)
|
S.restrict (url `S.like` S.the pattern)
|
||||||
return S.true
|
return S.true
|
||||||
-- turns domains into patterns to match a url
|
-- turns domains into patterns to match a url
|
||||||
pattern domain = "http%://%" <> domain <> "/"
|
mkPattern domain = "http%://%" <> domain <> "/"
|
||||||
|
|
||||||
|
|
||||||
-- | Deletes per-domain files under the IndexedDB directory
|
-- | Deletes per-domain files under the IndexedDB directory
|
||||||
@ -429,14 +420,12 @@ deleteSessionStorage = do
|
|||||||
-- * Helper functions
|
-- * Helper functions
|
||||||
|
|
||||||
-- | Loads a leveldb database and runs a resourceT action
|
-- | Loads a leveldb database and runs a resourceT action
|
||||||
--
|
withDB :: FilePath -> (L.DB -> ResourceT IO a) -> Action a
|
||||||
-- withDB :: FilePath -> (L.DB -> ResourceT IO a) -> Action a
|
|
||||||
withDB path f = liftIO $ L.runResourceT (L.open path def >>= f)
|
withDB path f = liftIO $ L.runResourceT (L.open path def >>= f)
|
||||||
|
|
||||||
|
|
||||||
-- | Like 'withDB' but retry the action after repairing the db
|
-- | Like 'withDB' but retry the action after repairing the db
|
||||||
--
|
withRetryDB :: FilePath -> (L.DB -> ResourceT IO a) -> Action a
|
||||||
-- withRetryDB :: FilePath -> (L.DB -> ResourceT IO a) -> Action a
|
|
||||||
withRetryDB path action = do
|
withRetryDB path action = do
|
||||||
res <- CE.try (withDB path action)
|
res <- CE.try (withDB path action)
|
||||||
case res of
|
case res of
|
||||||
@ -458,17 +447,20 @@ withRetryDB path action = do
|
|||||||
-- SQLite manages concurrent access via POSIX locks: these are tied to a
|
-- SQLite manages concurrent access via POSIX locks: these are tied to a
|
||||||
-- specific file and pid. They can be bypassed by simply creating a hard
|
-- specific file and pid. They can be bypassed by simply creating a hard
|
||||||
-- link (pointing to the same inode), editing the link and then removing it.
|
-- link (pointing to the same inode), editing the link and then removing it.
|
||||||
bypassLocks :: String -> (FilePath -> Action a) -> Action a
|
withoutLocks :: String -> (FilePath -> Action a) -> Action a
|
||||||
bypassLocks dbName cont = do
|
withoutLocks dbName cont = do
|
||||||
dir <- asks webenginePath
|
dir <- asks webenginePath
|
||||||
|
unsafe <- asks (unsafe . options)
|
||||||
let
|
let
|
||||||
real = dir </> dbName
|
real = dir </> dbName
|
||||||
link = real <> "-bypass"
|
link = real <> "-bypass"
|
||||||
-- bypass the SQLite POSIX locks with hard links
|
-- bypass the SQLite POSIX locks with hard links
|
||||||
liftIO (Posix.createLink real link)
|
when unsafe $ liftIO (Posix.createLink real link)
|
||||||
res <- cont database
|
|
||||||
|
res <- cont (if unsafe then link else real)
|
||||||
|
|
||||||
-- remove the hard links
|
-- remove the hard links
|
||||||
liftIO (Posix.removeLink link)
|
when unsafe $ liftIO (Posix.removeLink link)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@ executable bisc
|
|||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
build-depends: base ==4.* , selda ==0.*,
|
build-depends: base ==4.* , selda ==0.*,
|
||||||
selda-sqlite ==0.*,
|
selda-sqlite ==0.*,
|
||||||
leveldb-haskell ==0.*,
|
leveldb-haskell ==0.*, resourcet,
|
||||||
filepath, directory, text,
|
filepath, directory, text, unix,
|
||||||
mtl, configurator, exceptions,
|
mtl, configurator, exceptions,
|
||||||
data-default, bytestring,
|
data-default, bytestring,
|
||||||
optparse-applicative
|
optparse-applicative
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall -Wno-name-shadowing
|
||||||
if flag(static)
|
if flag(static)
|
||||||
extra-libraries: snappy stdc++
|
extra-libraries: snappy stdc++
|
||||||
|
Loading…
Reference in New Issue
Block a user