From 7196fcc54cb5671f21e4b905c1ce9884466b619c Mon Sep 17 00:00:00 2001 From: Dmitry Zuykov Date: Tue, 13 May 2025 07:59:12 +0300 Subject: [PATCH] wip --- hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs | 30 ++++++++++++++---------- hbs2-tests/test/TestCQ.hs | 5 ++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs index 9429300e..51100dc1 100644 --- a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs +++ b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ.hs @@ -141,8 +141,8 @@ data Location = instance Pretty Location where pretty = \case - InWriteQueue{} -> "write-queue" - InCurrent (o,l) -> pretty $ mkForm @C "current" [mkInt o, mkInt l] + InWriteQueue{} -> "write-queue" + InCurrent (o,l) -> pretty $ mkForm @C "current" [mkInt o, mkInt l] InFossil _ (o,l) -> pretty $ mkForm @C "fossil " [mkList [mkInt o, mkInt l]] type IsHCQKey h = ( Eq (Key h) @@ -214,17 +214,18 @@ ncqAddCachedSTM now limit tv k v = do writeTVar tv (HPSQ.insert k now v dst) - ncqAddTrackedFilesIO :: MonadIO m => NCQStorage -> [FilePath] -> m () ncqAddTrackedFilesIO ncq fps = do - tsFiles <- catMaybes <$> forM fps \fp -> liftIO $ do + tsFiles <- catMaybes <$> forM fps \fp' -> liftIO $ do catchIOError (do - stat <- getFileStatus fp + let fp = fromString fp' + let dataFile = ncqGetDataFileName ncq fp + stat <- getFileStatus dataFile let ts = modificationTimeHiRes stat - pure $ Just (FileKey (fromString fp), TimeSpec (floor ts) 0)) + pure $ Just (fp, TimeSpec (floor ts) 0)) (\e -> do - err $ "ncqAddTrackedFilesIO: failed to stat " <+> pretty fp <+> pretty (displayException e) + err $ "ncqAddTrackedFilesIO: failed to stat " <+> viaShow e pure Nothing) atomically $ ncqAddTrackedFilesSTM ncq tsFiles @@ -239,13 +240,16 @@ ncqAddTrackedFilesSTM NCQStorage{..} keys = do writeTVar ncqTrackedFiles new +ncqListTrackedFiles :: MonadIO m => NCQStorage -> m [FilePath] +ncqListTrackedFiles ncq = do + let wd = ncqGetCurrentDir ncq + dirFiles wd + >>= mapM (pure . takeBaseName) + <&> List.filter (List.isPrefixOf "fossil-") + ncqReadTrackedFiles :: MonadIO m => NCQStorage -> m () ncqReadTrackedFiles ncq@NCQStorage{} = do - - files <- dirFiles (ncqGetCurrentDir ncq) - >>= mapM (pure . takeBaseName) - <&> List.filter (List.isPrefixOf "fossil-") - + files <- ncqListTrackedFiles ncq ncqAddTrackedFilesIO ncq files ncqWriteError :: MonadIO m => NCQStorage -> Text -> m () @@ -943,6 +947,7 @@ ncqStorageInit_ check path = do when (lastSz /= currSz ) do fossilized <- ncqGetNewFossilName ncq0 + debug $ "NEW FOSSIL FILE" <+> pretty fossilized let fn = takeFileName fossilized let msg = fromString $ show $ "wrong-size" <+> pretty lastSz <+> pretty fn err $ pretty msg @@ -979,5 +984,6 @@ withNCQ setopts p action = flip runContT pure do link writer e <- lift (action ncq) lift (ncqStorageStop ncq) + wait writer pure e diff --git a/hbs2-tests/test/TestCQ.hs b/hbs2-tests/test/TestCQ.hs index 9a0007c8..7c04828a 100644 --- a/hbs2-tests/test/TestCQ.hs +++ b/hbs2-tests/test/TestCQ.hs @@ -249,6 +249,11 @@ main = do e -> throwIO $ BadFormException @C (mkList e) + entry $ bindMatch "test:ncq:raw:list-tracked-files" $ nil_ \case + [StringLike fn] -> lift $ withNCQ id fn $ \ncq -> do + ncqListTrackedFiles ncq >>= mapM_ display_ + + e -> throwIO $ BadFormException @C (mkList e) entry $ bindMatch "test:ncq:raw:get:stdout" $ nil_ \case