aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Caching.hs
diff options
context:
space:
mode:
authorpacien2020-06-13 10:58:00 +0200
committerpacien2020-06-16 18:23:25 +0200
commit8905383e2d17e2adb4097e1ce2e7f90ab9ceb5f5 (patch)
tree70be5303eb820e5a010be5b9e9a0e69e7313636f /compiler/src/Caching.hs
parentce2210e6deff1d981186b6d7ddb1176f27e41f49 (diff)
downloadldgallery-8905383e2d17e2adb4097e1ce2e7f90ab9ceb5f5.tar.gz
compiler: split ItemProcessors, FileProcessors and Caching
Diffstat (limited to 'compiler/src/Caching.hs')
-rw-r--r--compiler/src/Caching.hs56
1 files changed, 56 insertions, 0 deletions
diff --git a/compiler/src/Caching.hs b/compiler/src/Caching.hs
new file mode 100644
index 0000000..b2b1ee1
--- /dev/null
+++ b/compiler/src/Caching.hs
@@ -0,0 +1,56 @@
1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery.
3--
4-- Copyright (C) 2019-2020 Pacien TRAN-GIRARD
5--
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
8-- published by the Free Software Foundation, either version 3 of the
9-- License, or (at your option) any later version.
10--
11-- This program is distributed in the hope that it will be useful,
12-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-- GNU Affero General Public License for more details.
15--
16-- You should have received a copy of the GNU Affero General Public License
17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19module Caching
20 ( Cache
21 , skipCache
22 , withCache
23 ) where
24
25
26import Control.Monad (when)
27import System.Directory (removePathForcibly, doesDirectoryExist, doesFileExist)
28
29import FileProcessors (FileProcessor)
30import Files
31
32
33type Cache = FileProcessor -> FileProcessor
34
35skipCache :: Cache
36skipCache processor inputPath outputPath =
37 removePathForcibly outputPath
38 >> processor inputPath outputPath
39
40withCache :: Cache
41withCache processor inputPath outputPath =
42 do
43 isDir <- doesDirectoryExist outputPath
44 when isDir $ removePathForcibly outputPath
45
46 fileExists <- doesFileExist outputPath
47 if fileExists then
48 do
49 needUpdate <- isOutdated True inputPath outputPath
50 if needUpdate then update else skip
51 else
52 update
53
54 where
55 update = processor inputPath outputPath
56 skip = putStrLn $ "Skipping:\t" ++ outputPath