From ef93be6c2c8685176de5681bc7ebd349cd21d789 Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Wed, 5 Jun 2024 17:59:33 +0200
Subject: add `listAllFiles`

---
 src/Store/Store.hs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'src/Store')

diff --git a/src/Store/Store.hs b/src/Store/Store.hs
index b58a2da..e0bbdfb 100644
--- a/src/Store/Store.hs
+++ b/src/Store/Store.hs
@@ -3,6 +3,7 @@ module Store.Store
     withStore,
     withCommit,
     listFiles,
+    listAllFiles,
     readFile,
     writeFile,
     deleteFile,
@@ -116,6 +117,25 @@ listFiles :: FilePath -> StoreM [FilePath]
 listFiles =
   fmap (filter (not . (isSuffixOf "/"))) . listDirectory
 
+listAllFiles :: StoreM [FilePath]
+listAllFiles = 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
+
 data DoesNotExist = DoesNotExist String FilePath
   deriving (Show)
 
-- 
cgit v1.2.3