From 67c6dd475fe4ba883ddcfeb251241c362e9eb400 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 20 Nov 2016 08:14:03 +0100 Subject: [PATCH] make migration rerunnable --- Migrations/0.1.3.3-0.1.4.0/Migration.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Migrations/0.1.3.3-0.1.4.0/Migration.hs b/Migrations/0.1.3.3-0.1.4.0/Migration.hs index 5e87ef5..5016af5 100755 --- a/Migrations/0.1.3.3-0.1.4.0/Migration.hs +++ b/Migrations/0.1.3.3-0.1.4.0/Migration.hs @@ -3,6 +3,7 @@ import Database.HDBC.PostgreSQL import System.IO import System.Directory import Control.Exception +import Control.Monad (when) import Data.Maybe (fromJust) import qualified Data.Text as T import qualified Data.ByteString.Char8 as B @@ -78,7 +79,10 @@ main = do pPix = scale (pWidth, pHeight) orig savePngImage tPath $ ImageRGBA8 tPix savePngImage pPath $ ImageRGBA8 pPix - mapM (removeFile . (FP.) pathPrefix) [oldThumbName, oldPrevName] + mapM (\x -> do + let fullpath = pathPrefix FP. x + dfe <- doesFileExist fullpath + when dfe (removeFile fullpath)) [oldThumbName, oldPrevName] return [SqlByteString (B.pack $ '/':tPath), SqlByteString (B.pack $ '/':pPath), theId] _ -> error "malformed entry"