mirror of https://github.com/voidlizard/hbs2
wip, fuckup recovery
This commit is contained in:
parent
4b683a8713
commit
3ef135a25c
|
@ -96,6 +96,7 @@ data NCQStorageException =
|
||||||
| NCQStorageTimeout
|
| NCQStorageTimeout
|
||||||
| NCQStorageCurrentAlreadyOpen
|
| NCQStorageCurrentAlreadyOpen
|
||||||
| NCQStorageCantOpenCurrent
|
| NCQStorageCantOpenCurrent
|
||||||
|
| NCQStorageBrokenCurrent
|
||||||
| NCQMergeInvariantFailed String
|
| NCQMergeInvariantFailed String
|
||||||
deriving stock (Show,Typeable)
|
deriving stock (Show,Typeable)
|
||||||
|
|
||||||
|
@ -310,11 +311,13 @@ ncqReadTrackedFiles ncq@NCQStorage{} = do
|
||||||
files <- ncqListTrackedFiles ncq
|
files <- ncqListTrackedFiles ncq
|
||||||
ncqAddTrackedFilesIO ncq files
|
ncqAddTrackedFilesIO ncq files
|
||||||
|
|
||||||
ncqWriteError :: MonadIO m => NCQStorage -> Text -> m ()
|
ncqWriteError :: (MonadIO m) => NCQStorage -> Doc AnsiStyle -> m ()
|
||||||
ncqWriteError ncq txt = liftIO do
|
ncqWriteError ncq txt = liftIO do
|
||||||
p <- getPOSIXTime <&> round @_ @Integer
|
p <- getPOSIXTime <&> round @_ @Integer
|
||||||
let msg = Text.pack $ show $ "error" <+> fill 12 (pretty p) <+> pretty txt <> line
|
let msg = "error" <+> fill 12 (pretty p) <+> txt
|
||||||
Text.appendFile (ncqGetErrorLogName ncq) msg
|
err msg
|
||||||
|
let msgTxt = fromString $ show (msg <> line)
|
||||||
|
Text.appendFile (ncqGetErrorLogName ncq) msgTxt
|
||||||
|
|
||||||
ncqIndexFile :: MonadUnliftIO m => NCQStorage -> FilePath -> m FilePath
|
ncqIndexFile :: MonadUnliftIO m => NCQStorage -> FilePath -> m FilePath
|
||||||
ncqIndexFile n@NCQStorage{} fp' = do
|
ncqIndexFile n@NCQStorage{} fp' = do
|
||||||
|
@ -973,12 +976,26 @@ ncqFixIndexes ncq@NCQStorage{..} = do
|
||||||
|
|
||||||
ncqStorageOpen :: MonadUnliftIO m => FilePath -> m NCQStorage
|
ncqStorageOpen :: MonadUnliftIO m => FilePath -> m NCQStorage
|
||||||
ncqStorageOpen fp' = do
|
ncqStorageOpen fp' = do
|
||||||
|
flip fix 0 $ \next i -> do
|
||||||
fp <- liftIO $ makeAbsolute fp'
|
fp <- liftIO $ makeAbsolute fp'
|
||||||
ncq@NCQStorage{..} <- ncqStorageInit_ False fp
|
ncq@NCQStorage{..} <- ncqStorageInit_ False fp
|
||||||
ncqReadTrackedFiles ncq
|
ncqReadTrackedFiles ncq
|
||||||
ncqFixIndexes ncq
|
ncqFixIndexes ncq
|
||||||
ncqLoadIndexes ncq
|
ncqLoadIndexes ncq
|
||||||
readCurrent ncq
|
|
||||||
|
readCurrent ncq `catch` \case
|
||||||
|
NCQStorageBrokenCurrent | i < 2 -> do
|
||||||
|
let fn = ncqGetCurrentName ncq
|
||||||
|
let msg = "broken file" <+> pretty (takeFileName fn)
|
||||||
|
ncqWriteError ncq msg
|
||||||
|
let (p,tpl) = splitFileName (dropExtension fn `addExtension` ".broken")
|
||||||
|
newFn <- liftIO $ emptyTempFile p tpl
|
||||||
|
mv fn newFn
|
||||||
|
rm (ncqGetCurrentSizeName ncq)
|
||||||
|
void $ next (succ i)
|
||||||
|
|
||||||
|
e -> throwIO e
|
||||||
|
|
||||||
atomically $ putTMVar ncqOpenDone True
|
atomically $ putTMVar ncqOpenDone True
|
||||||
pure ncq
|
pure ncq
|
||||||
|
|
||||||
|
@ -999,8 +1016,7 @@ ncqStorageOpen fp' = do
|
||||||
let p = BS.take w (BS.drop 4 bs)
|
let p = BS.take w (BS.drop 4 bs)
|
||||||
|
|
||||||
when (BS.length p < w ) do
|
when (BS.length p < w ) do
|
||||||
err $ "broken file" <+> pretty fn
|
throwIO NCQStorageBrokenCurrent
|
||||||
exit ()
|
|
||||||
|
|
||||||
let k = BS.take 32 p & coerce . BS.copy
|
let k = BS.take 32 p & coerce . BS.copy
|
||||||
let vs = w - 32
|
let vs = w - 32
|
||||||
|
@ -1120,8 +1136,7 @@ ncqStorageInit_ check path = do
|
||||||
fossilized <- ncqGetNewFossilName ncq0
|
fossilized <- ncqGetNewFossilName ncq0
|
||||||
debug $ "NEW FOSSIL FILE" <+> pretty fossilized
|
debug $ "NEW FOSSIL FILE" <+> pretty fossilized
|
||||||
let fn = takeFileName fossilized
|
let fn = takeFileName fossilized
|
||||||
let msg = fromString $ show $ "wrong-size" <+> pretty lastSz <+> pretty fn
|
let msg = "wrong-size" <+> pretty lastSz <+> pretty fn
|
||||||
err $ pretty msg
|
|
||||||
ncqWriteError ncq0 msg
|
ncqWriteError ncq0 msg
|
||||||
mv currentName fossilized
|
mv currentName fossilized
|
||||||
PFS.setFileSize fossilized (fromIntegral lastSz)
|
PFS.setFileSize fossilized (fromIntegral lastSz)
|
||||||
|
|
Loading…
Reference in New Issue