aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Files.hs
diff options
context:
space:
mode:
authorpacien2020-01-05 15:31:38 +0100
committerpacien2020-01-05 15:31:38 +0100
commitabdf82bbfde843a87bd00746f52dafdd28f3f60b (patch)
tree252c734cdbc2edc6d85c76a0f0d9422fb95fe4d9 /compiler/src/Files.hs
parent5367781f0c7fd1ce274492ba91895fef9d44dab3 (diff)
downloadldgallery-abdf82bbfde843a87bd00746f52dafdd28f3f60b.tar.gz
compiler: make absent file names more explicit
Diffstat (limited to 'compiler/src/Files.hs')
-rw-r--r--compiler/src/Files.hs39
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 @@
25module Files 25module 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
84fileName :: Path -> FileName 84fileName :: Path -> Maybe FileName
85fileName (Path (name:_)) = name 85fileName (Path (name:_)) = Just name
86 86fileName _ = Nothing
87maybeFileName :: Path -> Maybe FileName
88maybeFileName (Path (name:_)) = Just name
89maybeFileName _ = Nothing
90 87
91subPaths :: Path -> [Path] 88subPaths :: Path -> [Path]
92subPaths (Path path) = map Path $ subsequences path 89subPaths (Path path) = map Path $ subsequences path
@@ -101,21 +98,25 @@ webPath :: Path -> WebPath
101webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path 98webPath (Path path) = System.FilePath.Posix.joinPath $ reverse path
102 99
103 100
104data FSNode = File Path | Dir Path [FSNode] deriving Show 101data FSNode =
102 File { path :: Path }
103 | Dir { path :: Path, items :: [FSNode] }
104 deriving Show
105
105data AnchoredFSNode = AnchoredFSNode 106data AnchoredFSNode = AnchoredFSNode
106 { anchor :: LocalPath 107 { anchor :: LocalPath
107 , root :: FSNode } deriving Show 108 , root :: FSNode }
109 deriving Show
108 110
109nodePath :: FSNode -> Path 111nodeName :: FSNode -> Maybe FileName
110nodePath (File path) = path 112nodeName = fileName . path
111nodePath (Dir path _) = path
112
113nodeName :: FSNode -> FileName
114nodeName = fileName . nodePath
115 113
116isHidden :: FSNode -> Bool 114isHidden :: FSNode -> Bool
117isHidden node = "." `isPrefixOf` filename &&length filename > 1 115isHidden = 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.
121flattenDir :: FSNode -> [FSNode] 122flattenDir :: FSNode -> [FSNode]