🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

Commit 9cbe6eb1180919f49e184775e8a2ef383cf56952
Parent: 4813a57bdfb2349f0bcc3c01591278bef42e11d4
Author: mcol <mcol@posteo.net>
Date: 2021-11-28 18:05:09 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-28 18:05:09 +0000

handle existing symlinks in output more robustly

src/Templates.hs Modified

@@ -13,16 +13,15 @@
 import Control.Monad.IO.Class (liftIO)
 import Control.Monad.Trans.Reader (ReaderT)
 import qualified Data.HashMap.Strict as HashMap
-import Data.Maybe (catMaybes)
+import Data.Maybe (catMaybes, fromMaybe)
 import Data.Text (Text, unpack)
 import Git.Libgit2 (LgRepo)
 import Path (Abs, Dir, File, Path, Rel, dirname, filename, parseAbsDir, toFilePath, (</>))
-import Path.IO (copyDirRecur, copyFile, doesDirExist, ensureDir, listDir)
+import Path.IO (copyDirRecur, copyFile, doesDirExist, ensureDir, forgivingAbsence, isSymlink, listDir)
 import System.Directory (
     canonicalizePath,
     createDirectoryLink,
     createFileLink,
-    doesPathExist,
     getSymbolicLinkTarget,
     pathIsSymbolicLink,
     removeFile,
@@ -215,7 +214,8 @@
         if isLink
             then do
                 target <- getSymbolicLinkTarget fp
-                exists <- doesPathExist . toFilePath $ output'
+                maybeExists <- forgivingAbsence . isSymlink $ output'
+                let exists = fromMaybe False maybeExists
                 when exists . removeFile . toFilePath $ output'
                 createFileLink target . toFilePath $ output'
             else copyFile p output'