diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-06-05 23:28:54 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-06-05 23:35:23 +0200 |
commit | 906d9ebba1ae08ea73acb55b536ff2f49e1b55c0 (patch) | |
tree | b0353d9f730aad97fa2c33e753c16c9e2cd408c2 | |
parent | d8b2af98f594e4fc5cc4919c1efe95e1d8d9aafe (diff) |
drop `listAllFiles`
-rw-r--r-- | src/Store/Store.hs | 72 |
1 files changed, 26 insertions, 46 deletions
diff --git a/src/Store/Store.hs b/src/Store/Store.hs index 56113cf..1f41d8a 100644 --- a/src/Store/Store.hs +++ b/src/Store/Store.hs @@ -3,7 +3,6 @@ module Store.Store withStore, withCommit, listFiles, - listAllFiles, readFile, writeFile, deleteFile, @@ -24,7 +23,7 @@ import Data.Aeson qualified as J import Data.ByteString qualified as B import Data.ByteString.Lazy qualified as LB import Data.ByteString.UTF8 qualified as B -import Data.List (isPrefixOf, isSuffixOf, sort) +import Data.List (isPrefixOf, sort) import Data.Tagged (Tagged (Tagged), untag) import Data.Text qualified as T import Data.Text.Encoding qualified as T @@ -33,7 +32,7 @@ import Data.Time.Clock (getCurrentTime) import Foreign import Git qualified as G import Git.Libgit2 qualified as GB -import System.FilePath (addTrailingPathSeparator, hasDrive, joinDrive, makeRelative, normalise, splitPath) +import System.FilePath (makeRelative, normalise, (</>)) import Text.Printf (printf) import Prelude hiding (readFile, writeFile) @@ -91,51 +90,32 @@ withCommit cid action = do (evalStateT (runStoreT action) (State {cid, tid})) (Env {repo, ref}) -listDirectory :: FilePath -> StoreM [FilePath] -listDirectory dir' = do - State {tid} <- get - Env {repo} <- ask - lift $ G.runRepository GB.lgFactory repo $ do - let dir = normalise $ if hasDrive dir' then dir' else joinDrive "/" dir' - n = length (splitPath dir) - tree <- G.lookupTree tid - sort - . map (makeRelative dir) - . filter ((== n + 1) . length . splitPath) - . filter (isPrefixOf (addTrailingPathSeparator dir)) - . map fst - . map - ( \e -> - case snd e of - G.BlobEntry _ _ -> e - G.CommitEntry _ -> error "XXX commit entry" - G.TreeEntry _ -> first addTrailingPathSeparator e - ) - . map (first (("/" <>) . B.toString)) - <$> G.listTreeEntries tree - listFiles :: FilePath -> StoreM [FilePath] -listFiles = - fmap (filter (not . (isSuffixOf "/"))) . listDirectory - -listAllFiles :: StoreM [FilePath] -listAllFiles = do +listFiles (normalise . ("/" </>) -> fp) = do State {tid} <- get - Env {repo} <- ask - lift $ G.runRepository GB.lgFactory repo $ do - tree <- G.lookupTree tid - filter (not . isSuffixOf "/") - . sort - . map fst - . map - ( \e -> - case snd e of - G.BlobEntry _ _ -> e - G.CommitEntry _ -> error "XXX commit entry" - G.TreeEntry _ -> first addTrailingPathSeparator e - ) - . map (first (("/" <>) . B.toString)) - <$> G.listTreeEntries tree + map (makeRelative fp) + . filter (fp `isPrefixOf`) + . map ("/" </>) + <$> listTree tid + where + listTree :: G.TreeOid GB.LgRepo -> StoreM [FilePath] + listTree tid = do + Env {repo} <- ask + fmap sort . lift $ G.runRepository GB.lgFactory repo $ do + listTree' repo tid + + listTree' repo tid = + fmap concat + . mapM + ( \(fp, e) -> + case e of + G.BlobEntry _ _ -> pure [fp] + G.CommitEntry _ -> error "XXX commit entry" + G.TreeEntry tid' -> pure [] + ) + . map (first B.toString) + =<< G.listTreeEntries + =<< G.lookupTree tid data DoesNotExist = DoesNotExist String FilePath deriving (Show) |