diff options
Diffstat (limited to 'compiler/src/Files.hs')
-rw-r--r-- | compiler/src/Files.hs | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs index a658ded..53f9c9e 100644 --- a/compiler/src/Files.hs +++ b/compiler/src/Files.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | 1 | -- ldgallery - A static generator which turns a collection of tagged |
2 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
3 | -- | 3 | -- |
4 | -- Copyright (C) 2019 Pacien TRAN-GIRARD | 4 | -- Copyright (C) 2019-2020 Pacien TRAN-GIRARD |
5 | -- | 5 | -- |
6 | -- This program is free software: you can redistribute it and/or modify | 6 | -- This program is free software: you can redistribute it and/or modify |
7 | -- it under the terms of the GNU Affero General Public License as | 7 | -- it under the terms of the GNU Affero General Public License as |
@@ -25,10 +25,10 @@ | |||
25 | module Files | 25 | module Files |
26 | ( FileName, LocalPath, WebPath, Path | 26 | ( FileName, LocalPath, WebPath, Path |
27 | , (</>), (</), (/>), (<.>) | 27 | , (</>), (</), (/>), (<.>) |
28 | , fileName, maybeFileName, subPaths, pathLength | 28 | , fileName, subPaths, pathLength |
29 | , localPath, webPath | 29 | , localPath, webPath |
30 | , FSNode(..), AnchoredFSNode(..) | 30 | , FSNode(..), AnchoredFSNode(..) |
31 | , nodePath, nodeName, isHidden, flattenDir, filterDir | 31 | , nodeName, isHidden, flattenDir, filterDir |
32 | , readDirectory, copyTo | 32 | , readDirectory, copyTo |
33 | , ensureParentDir, remove, isOutdated | 33 | , ensureParentDir, remove, isOutdated |
34 | ) where | 34 | ) where |
@@ -81,12 +81,9 @@ file /> (Path path) = Path (path ++ [file]) | |||
81 | (Path (filename:pathto)) <.> ext = | 81 | (Path (filename:pathto)) <.> ext = |
82 | Path $ System.FilePath.addExtension filename ext : pathto | 82 | Path $ System.FilePath.addExtension filename ext : pathto |
83 | 83 | ||
84 | fileName :: Path -> FileName | 84 | fileName :: Path -> Maybe FileName |
85 | fileName (Path (name:_)) = name | 85 | fileName (Path (name:_)) = Just name |
86 | 86 | fileName _ = Nothing | |
87 | maybeFileName :: Path -> Maybe FileName | ||
88 | maybeFileName (Path (name:_)) = Just name | ||
89 | maybeFileName _ = Nothing | ||
90 | 87 | ||
91 | subPaths :: Path -> [Path] | 88 | subPaths :: Path -> [Path] |
92 | subPaths (Path path) = map Path $ subsequences path | 89 | subPaths (Path path) = map Path $ subsequences path |
@@ -101,21 +98,25 @@ webPath :: Path -> WebPath | |||
101 | webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path | 98 | webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path |
102 | 99 | ||
103 | 100 | ||
104 | data FSNode = File Path | Dir Path [FSNode] deriving Show | 101 | data FSNode = |
102 | File { path :: Path } | ||
103 | | Dir { path :: Path, items :: [FSNode] } | ||
104 | deriving Show | ||
105 | |||
105 | data AnchoredFSNode = AnchoredFSNode | 106 | data AnchoredFSNode = AnchoredFSNode |
106 | { anchor :: LocalPath | 107 | { anchor :: LocalPath |
107 | , root :: FSNode } deriving Show | 108 | , root :: FSNode } |
109 | deriving Show | ||
108 | 110 | ||
109 | nodePath :: FSNode -> Path | 111 | nodeName :: FSNode -> Maybe FileName |
110 | nodePath (File path) = path | 112 | nodeName = fileName . path |
111 | nodePath (Dir path _) = path | ||
112 | |||
113 | nodeName :: FSNode -> FileName | ||
114 | nodeName = fileName . nodePath | ||
115 | 113 | ||
116 | isHidden :: FSNode -> Bool | 114 | isHidden :: FSNode -> Bool |
117 | isHidden node = "." `isPrefixOf` filename &&length filename > 1 | 115 | isHidden = hiddenName . nodeName |
118 | where filename = nodeName node | 116 | where |
117 | hiddenName :: Maybe FileName -> Bool | ||
118 | hiddenName Nothing = False | ||
119 | hiddenName (Just filename) = "." `isPrefixOf` filename && length filename > 1 | ||
119 | 120 | ||
120 | -- | DFS with intermediate dirs first. | 121 | -- | DFS with intermediate dirs first. |
121 | flattenDir :: FSNode -> [FSNode] | 122 | flattenDir :: FSNode -> [FSNode] |