Make missing static files directory non-fatal
Today, bmcweb requires the /usr/share/www directory to exist. In most
cases where bmcweb was installed with make install, this is fine, but in
development scenarios, we'd like to be able to boot.
This commit moves what used to be a fatal error (the directory not
existing) to a warning, to help with a common development issue I've
seen before.
Tested:
Launched without a /usr/share/www directory present, and bmcweb launched
successfully and did not throw an exception.
Change-Id: I775fafd86a4e2eef0bf73836d31a78fb320b61c0
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 3703c30..a4ec58b 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -52,7 +52,17 @@
{".map", "application/json"}}};
std::filesystem::path rootpath{"/usr/share/www/"};
- std::filesystem::recursive_directory_iterator dirIter(rootpath);
+
+ std::error_code ec;
+
+ std::filesystem::recursive_directory_iterator dirIter(rootpath, ec);
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "Unable to find or open " << rootpath
+ << " static file hosting disabled";
+ return;
+ }
+
// In certain cases, we might have both a gzipped version of the file AND a
// non-gzipped version. To avoid duplicated routes, we need to make sure we
// get the gzipped version first. Because the gzipped path should be longer