From 1d7299bced057e3c0e6cc76507fc25d6f493968e Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 14:33:44 +0100 Subject: example: simplify .gitignore --- example/.gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/example/.gitignore b/example/.gitignore index c5ae58b..1fcb152 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,3 +1 @@ out -items -thumbnails \ No newline at end of file -- cgit v1.2.3 From b757ee814c01c83b17b495c4805fcc70d7e08c89 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 15:08:46 +0100 Subject: compiler: simplify checks --- compiler/src/Compiler.hs | 8 ++------ compiler/src/Processors.hs | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index adc4a5f..2a0dccc 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -22,7 +22,7 @@ module Compiler ) where -import Control.Monad (liftM2) +import Control.Monad (liftM2, when) import Data.List (any) import System.FilePath (()) import qualified System.FilePath.Glob as Glob @@ -118,11 +118,7 @@ compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) resources <- galleryBuilder (galleryName config) inputTree - if cleanOutput then - galleryCleanupResourceDir resources outputDirPath - else - return () - + when cleanOutput $ galleryCleanupResourceDir resources outputDirPath writeJSON outputIndex resources writeJSON outputViewerConf $ viewer fullConfig diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs index 6ab4eb5..faa2f43 100644 --- a/compiler/src/Processors.hs +++ b/compiler/src/Processors.hs @@ -25,6 +25,7 @@ module Processors import Control.Exception (Exception, throwIO) +import Control.Monad (when) import Data.Function ((&)) import Data.Char (toLower) import Data.List (break) @@ -106,7 +107,7 @@ withCached :: Cache withCached processor inputPath outputPath = do isDir <- doesDirectoryExist outputPath - if isDir then removePathForcibly outputPath else noop + when isDir $ removePathForcibly outputPath fileExists <- doesFileExist outputPath if fileExists then @@ -117,7 +118,6 @@ withCached processor inputPath outputPath = update where - noop = return () update = processor inputPath outputPath skip = putStrLn $ "Skipping:\t" ++ outputPath -- cgit v1.2.3 From c22ea3de0fc5a42449b4bae80afa1a94c7afa41e Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 15:10:58 +0100 Subject: compiler: reject input and output directories that coincide GitHub: closes #80 --- compiler/app/Main.hs | 24 +++++++++++++++--------- ldgallery.1.md | 7 +++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1864dee..594a5b7 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -20,11 +20,13 @@ module Main where import GHC.Generics (Generic) import Paths_ldgallery_compiler (version, getDataFileName) +import Control.Monad (when) import Data.Version (showVersion) import Data.Int (Int64) import Data.Aeson (ToJSON) import Data.Time.Clock.System (getSystemTime, systemSeconds) import System.FilePath (()) +import System.Directory (canonicalizePath) import System.Console.CmdArgs import Compiler @@ -88,11 +90,9 @@ main = do opts <- cmdArgs options buildGallery opts - if (withViewer opts) then do + when (withViewer opts) $ do copyViewer (outputDir opts) writeViewerConfig (outputDir opts "config.json") - else - return () where gallerySubdir :: String @@ -100,12 +100,18 @@ main = buildGallery :: Options -> IO () buildGallery opts = - compileGallery - (inputDir opts) - (galleryOutputDir opts) - [outputDir opts] - (rebuilAll opts) - (cleanOutput opts) + checkDistinctPaths (inputDir opts) (outputDir opts) + >> compileGallery + (inputDir opts) + (galleryOutputDir opts) + [outputDir opts] + (rebuilAll opts) + (cleanOutput opts) + where + checkDistinctPaths a b = do + canonicalA <- canonicalizePath a + canonicalB <- canonicalizePath b + when (canonicalA == canonicalB) $ error "Input and output paths refer to the same location." galleryOutputDir :: Options -> FilePath galleryOutputDir opts = diff --git a/ldgallery.1.md b/ldgallery.1.md index 5612cbf..8928693 100644 --- a/ldgallery.1.md +++ b/ldgallery.1.md @@ -25,10 +25,13 @@ ldgallery [\--input-dir _./_] [\--output-dir _./out_] [\--with-viewer] Available options are: -i, \--input-dir _DIR_ -: Gallery source directory. Defaults to the current directory. +: Gallery source directory. + Defaults to the current directory. -o, \--output-dir _DIR_ -: Generated gallery output path. Defaults to ./out. +: Generated gallery output path. + Must be distinct from the source directory. + Defaults to ./out. -r, \--rebuild-all : Invalidate cache and recompile everything. -- cgit v1.2.3