Compare commits

...

2 Commits

3 changed files with 57 additions and 1 deletions

44
backfill.sh Executable file
View File

@ -0,0 +1,44 @@
#!/run/current-system/sw/bin/bash
set -e
# Ensure two arguments are provided: paths file and settings file
if [[ "$#" -ne 2 ]]; then
echo "Usage: $0 PATHS_FILE SETTINGS_FILE"
exit 1
fi
PATHS_FILE="$1"
SETTINGS_FILE="$2"
# Ensure the paths file exists
if [[ ! -f "$PATHS_FILE" ]]; then
echo "Error: Paths file '$PATHS_FILE' not found!"
exit 1
fi
# Ensure the settings file exists
if [[ ! -f "$SETTINGS_FILE" ]]; then
echo "Error: Settings file '$SETTINGS_FILE' not found!"
exit 1
fi
PROG="./dist-newstyle/build/x86_64-linux/ghc-9.2.8/chan-delorean-0.0.1/x/chan-delorean/build/chan-delorean/chan-delorean"
# Ensure your_program is compiled and available
if ! command -v $PROG >/dev/null; then
echo "Error: your_program is not compiled or not in the PATH!"
exit 1
fi
# Loop through each line of the paths file
while IFS= read -r BACKUP_PATH; do
# Update backup_read_root in the settings file using sed
sed -e 's|\("backup_read_root": \)".*"|\1"'"$BACKUP_PATH"'"|' "$SETTINGS_FILE" > "temp_$SETTINGS_FILE"
# Run the Haskell program with the updated settings file
$PROG +RTS -N2 -RTS "temp_$SETTINGS_FILE"
done < "$PATHS_FILE"
# Optionally, remove the temporary settings file
rm "temp_$SETTINGS_FILE"

View File

@ -172,7 +172,7 @@ readPosts settings board thread = do
case result of
Left err -> do
putStrLn $ "Failed to parse the JSON file " ++ thread_filename ++ " error: " ++ err
exitFailure
return (thread, [])
Right posts_wrapper -> return $ (thread, JSONPosts.posts posts_wrapper)
where

View File

@ -8,6 +8,7 @@ module JSONParsing
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception.Safe (tryAny)
import Data.Text (Text)
import GHC.Generics
import qualified Data.ByteString.Lazy as B
@ -51,5 +52,16 @@ instance FromJSON Catalog
parseJSONCatalog :: FilePath -> IO (Either String [Catalog])
parseJSONCatalog path = B.readFile path >>= return . eitherDecode
{-
parsePosts :: FilePath -> IO (Either String Post.PostWrapper)
parsePosts path = B.readFile path >>= return . eitherDecode
-}
parsePosts :: FilePath -> IO (Either String Post.PostWrapper)
parsePosts path = do
fileResult <- tryAny (B.readFile path)
case fileResult of
Left e -> return . Left $ "Error reading file: " ++ show e
Right content -> return . eitherDecode $ content