Fix crash on rebuild

Fixed a bug which caused SWG to crash when rebuilding a website which
has been build before (a website with an existing "output" directory).
This commit is contained in:
luca0N! 2022-03-22 17:27:40 -03:00
parent d424e85466
commit 46bd5333a8
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 16 additions and 5 deletions

View File

@ -208,19 +208,30 @@ void build_website(SwgContext &ctx, std::string const &path) {
getFilename(ws_entry.path()).length());
if (!std::filesystem::exists(copied_subdir)) {
std::filesystem::create_directories(copied_subdir);
std::cout << "--> Creating: " << copied_subdir << "\n";
std::cout << "Creating: " << copied_subdir << "\n";
}
// If this isn't a Markdown file, just copy it.
if (currentFile.find(".md") == std::string::npos)
std::filesystem::copy(ws_entry, copied_subdir);
else {
bool compiled = false;
if (currentFile.find(".md") == std::string::npos) {
try {
std::filesystem::copy(ws_entry, copied_subdir);
} catch (std::filesystem::filesystem_error const &cpyErr) {
// Ignore exception if it was
// thrown due to an existing
// file error while copying.
if (cpyErr.code().value() != 17)
throw cpyErr;
}
} else {
// This is a Markdown file. Compile a HTML version.
std::filesystem::path output_html = copied_subdir;
// Remove the .md extension and use the HTML extension instead
output_html /= currentFile.substr(0, currentFile.length() - 3) + ".html";
compile_markdown(path, ws_entry.path(), output_html);
compiled = true;
}
std::cout << "\t!: " << ws_entry.path().string().substr(path.length()) << "\n";
std::cout << (compiled ? "Compiled: " : "Copied: ") <<
ws_entry.path().string().substr(path.length()) << "\n";
}
}
} catch (std::filesystem::filesystem_error const &e) {