From 0fddc74a3f9add47841124b4d77b097f4646d14f Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:05:45 +0200 Subject: compiler: fix support for non-utf8 terminals The compiler echoes the names of the files being processed. Those file names may contain UTF-8 characters. However, some consoles may not support those. This is notably the case of the Windows CMD or on Linux with the legacy C locale. This caused the following error: ldgallery: : commitBuffer: invalid argument (invalid character) This patch adds automatic transliteration when a non-UTF8 terminal is detected, so that neither the compiler or the terminal crash due to UTF8 characters. GitHub: closes #341 --- compiler/app/Main.hs | 5 +++-- compiler/package.yaml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'compiler') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 3e6f254..a9630ce 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -28,6 +28,7 @@ import Data.Aeson (ToJSON) import System.FilePath (()) import System.Directory (canonicalizePath, listDirectory) import System.Console.CmdArgs +import Main.Utf8 (withUtf8) import Compiler import Files (readDirectory, copyTo, remove) @@ -103,7 +104,7 @@ options = Options main :: IO () main = - do + withUtf8 $ do opts <- cmdArgs options buildGallery opts deployViewer opts diff --git a/compiler/package.yaml b/compiler/package.yaml index 7bd86e9..0c07efe 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -4,7 +4,7 @@ homepage: https://ldgallery.pacien.org github: "pacien/ldgallery" license: AGPL-3 author: "Pacien TRAN-GIRARD, Guillaume FOUET" -copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" +copyright: "2019-2022 Pacien TRAN-GIRARD, Guillaume FOUET" extra-source-files: - readme.md @@ -29,6 +29,7 @@ dependencies: - safe - time - process +- with-utf8 default-extensions: - DuplicateRecordFields -- cgit v1.2.3 From f23c5e5b2cc837093e029884eae1f2edeaa4c888 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:31:47 +0200 Subject: compiler: add log messages for early steps This adds some messages signaling that the compiler is doing something when it is enumerating the input tree and reading metadata files, which may take a while on systems with slow IO such as when using a network share. GitHub: closes #344 --- compiler/src/Compiler.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 4111f02..d92d8e9 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -85,7 +85,8 @@ loadGalleryIndex path = doesFileExist path >>= bool (return Nothing) decodeIndex where decodeIndex = - JSON.eitherDecodeFileStrict path + putStrLn ("Loading previous index:\t" ++ path) + >> JSON.eitherDecodeFileStrict path >>= either (\err -> warn err >> return Nothing) (return . Just) warn = putStrLn . ("Warning:\tUnable to reuse existing index as cache: " ++) @@ -136,10 +137,13 @@ compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDir do config <- readConfig $ inputGalleryConf configPath + putStrLn "Inventorying input files" inputDir <- readDirectory inputDirPath excludedCanonicalDirs <- mapM canonicalizePath excludedDirs + let sourceFilter = galleryDirFilter config excludedCanonicalDirs let sourceTree = filterDir sourceFilter inputDir + putStrLn "Reading input metadata" inputTree <- readInputTree sourceTree let curatedInputTree = filterInputTree (inputTreeFilter config) inputTree -- cgit v1.2.3 From 7ae7e904303dd623398495c2d61d1acadfe96fb1 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:58:22 +0200 Subject: compiler: update stack resolver lts-16.19 -> lts-19.30 To have with-utf8 1.0.2.3, because 1.0.2.1 fails building on Windows with the following error: Module `GHC.IO.Encoding.Iconv' does not export `localeEncodingName' --- compiler/stack.yaml | 2 +- compiler/stack.yaml.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'compiler') diff --git a/compiler/stack.yaml b/compiler/stack.yaml index 67e823b..b75c56f 100644 --- a/compiler/stack.yaml +++ b/compiler/stack.yaml @@ -17,7 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-16.19 +resolver: lts-19.30 # User packages to be built. diff --git a/compiler/stack.yaml.lock b/compiler/stack.yaml.lock index 93f79d9..dc48671 100644 --- a/compiler/stack.yaml.lock +++ b/compiler/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 532177 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/19.yaml - sha256: d2b828ecf50386841d0c5700b58d38566992e10d63a062af497ab29ab031faa1 - original: lts-16.19 + sha256: 9a74d76d250a455d9cd11e74f157e087787fa9aa3c4264e69c94703d1e71aede + size: 619200 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/30.yaml + original: lts-19.30 -- cgit v1.2.3