diff options
author | pacien | 2019-12-26 01:13:42 +0100 |
---|---|---|
committer | pacien | 2019-12-26 01:13:42 +0100 |
commit | 2a6467272e18af4864745b9d0267f9fa3ed382dd (patch) | |
tree | a81672b9a0d7d9ad0577453c263cbd4d4d6f315c /compiler/src/Files.hs | |
parent | 45163fbc93b2bf2f7cb1fc3242ce5d3f51076601 (diff) | |
download | ldgallery-2a6467272e18af4864745b9d0267f9fa3ed382dd.tar.gz |
compiler: implement output dir cleanup
Diffstat (limited to 'compiler/src/Files.hs')
-rw-r--r-- | compiler/src/Files.hs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs index 30e4b94..77a8c5b 100644 --- a/compiler/src/Files.hs +++ b/compiler/src/Files.hs | |||
@@ -23,7 +23,7 @@ module Files | |||
23 | ( FileName, LocalPath, WebPath, Path | 23 | ( FileName, LocalPath, WebPath, Path |
24 | , (</>), (</), (/>), localPath, webPath | 24 | , (</>), (</), (/>), localPath, webPath |
25 | , FSNode(..), AnchoredFSNode(..) | 25 | , FSNode(..), AnchoredFSNode(..) |
26 | , nodePath, nodeName, isHidden, flatten, filterDir, readDirectory | 26 | , nodePath, nodeName, isHidden, flattenDir, filterDir, readDirectory |
27 | ) where | 27 | ) where |
28 | 28 | ||
29 | 29 | ||
@@ -76,9 +76,10 @@ isHidden :: FSNode -> Bool | |||
76 | isHidden node = "." `isPrefixOf` filename && length filename > 1 | 76 | isHidden node = "." `isPrefixOf` filename && length filename > 1 |
77 | where filename = nodeName node | 77 | where filename = nodeName node |
78 | 78 | ||
79 | flatten :: FSNode -> [FSNode] | 79 | -- | DFS with intermediate dirs first. |
80 | flatten file@(File _) = [file] | 80 | flattenDir :: FSNode -> [FSNode] |
81 | flatten dir@(Dir _ childs) = dir:(concatMap flatten childs) | 81 | flattenDir file@(File _) = [file] |
82 | flattenDir dir@(Dir _ childs) = dir:(concatMap flattenDir childs) | ||
82 | 83 | ||
83 | -- | Filters a dir tree. The root is always returned. | 84 | -- | Filters a dir tree. The root is always returned. |
84 | filterDir :: (FSNode -> Bool) -> FSNode -> FSNode | 85 | filterDir :: (FSNode -> Bool) -> FSNode -> FSNode |
@@ -87,7 +88,7 @@ filterDir cond (Dir path childs) = | |||
87 | filter cond childs & map (filterDir cond) & Dir path | 88 | filter cond childs & map (filterDir cond) & Dir path |
88 | 89 | ||
89 | readDirectory :: LocalPath -> IO AnchoredFSNode | 90 | readDirectory :: LocalPath -> IO AnchoredFSNode |
90 | readDirectory root = mkNode [""] >>= return . AnchoredFSNode root | 91 | readDirectory root = mkNode [] >>= return . AnchoredFSNode root |
91 | where | 92 | where |
92 | mkNode :: Path -> IO FSNode | 93 | mkNode :: Path -> IO FSNode |
93 | mkNode path = | 94 | mkNode path = |