From fb546ccec8d1641afae622e761eb7c9453f685c6 Mon Sep 17 00:00:00 2001 From: luca0N! Date: Sun, 24 Mar 2024 17:49:02 -0300 Subject: [PATCH] Fix configuration file I/O (#8) Due to a programming error introduced in commit 83ec72e80c, an instance of std::ifstream was being initialized with the path to the website directory (without the file name appended to the path). --- src/Common.hxx | 4 +++- src/ConfigUtils.cxx | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Common.hxx b/src/Common.hxx index a4a2b1b..259aa83 100644 --- a/src/Common.hxx +++ b/src/Common.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 luca0N! + * Copyright (C) 2022-2024 luca0N! * * This file is part of Static Website Generator (swg). * @@ -39,6 +39,8 @@ #include #include +const std::string SWG_CONFIG_FILENAME = "swg.cfg"; + struct Blog { char name[64], path[64], diff --git a/src/ConfigUtils.cxx b/src/ConfigUtils.cxx index 7395855..b97097e 100644 --- a/src/ConfigUtils.cxx +++ b/src/ConfigUtils.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 luca0N! + * Copyright (C) 2022-2024 luca0N! * * This file is part of Static Website Generator (swg). * @@ -34,8 +34,10 @@ void parse_config(SwgContext *ctx, std::string const &path) { int blogCount = 0; Blog *currentBlog = NULL; + std::ifstream cfgStream(path + "/" + SWG_CONFIG_FILENAME); + if (!cfgStream) + throw std::runtime_error("Couldn't find swg configuration file at the specified path: " + path); - std::ifstream cfgStream(path); // Parse configuration file for (std::string line; std::getline(cfgStream, line);) { // Skip comment lines