Module: check_mk
Branch: master
Commit: c9941ea6f2a8e40f5c5c2d22cfa2b4547be83222
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c9941ea6f2a8e4…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Feb 28 16:06:22 2017 +0100
More std::filesystem goodness.
Change-Id: I5dfc6a857e5b1eb7ff4e3559f1bf03ede172a6b8
---
livestatus/src/pnp4nagios.cc | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/livestatus/src/pnp4nagios.cc b/livestatus/src/pnp4nagios.cc
index c90d6c1..b0c77a8 100644
--- a/livestatus/src/pnp4nagios.cc
+++ b/livestatus/src/pnp4nagios.cc
@@ -22,12 +22,13 @@
// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA 02110-1301 USA.
+// IWYU pragma: no_include <experimental/bits/fs_ops.h>
+// IWYU pragma: no_include <experimental/fs_ops.h>
#include "pnp4nagios.h"
#include <cstddef>
-#ifdef CMC
-#include <sys/stat.h>
-#else
-#include <unistd.h>
+#include <system_error>
+#ifndef CMC
+#include "FileSystem.h"
#endif
using std::string;
@@ -54,34 +55,33 @@ string pnp_cleanup(const string& name) {
}
#ifndef CMC
+// TODO(sp) Merge this with Perfdatabase::getPNPXMLPath
int pnpgraph_present(const string& host, const string& service) {
- string pnp_path(g_pnp_path);
+ fs::path pnp_path = g_pnp_path;
if (pnp_path.empty()) {
return -1;
}
- string path(pnp_path.append(pnp_cleanup(host))
- .append("/")
- .append(pnp_cleanup(service))
- .append(".xml"));
- return access(path.c_str(), R_OK) == 0 ? 1 : 0;
+ fs::path path =
+ pnp_path / pnp_cleanup(host) / (pnp_cleanup(service) + ".xml");
+ std::error_code ec;
+ fs::status(path, ec);
+ return ec ? 0 : 1;
}
#endif
#ifdef CMC
+// TODO(sp) Merge this with Perfdatabase::getPNPRRDPath
fs::path rrd_path(const string& host, const string& service,
const string& varname) {
- string pnp_path(g_pnp_path);
+ fs::path pnp_path = g_pnp_path;
if (pnp_path.empty()) {
return "";
}
- string path(pnp_path.append("/")
- .append(pnp_cleanup(host))
- .append("/")
- .append(pnp_cleanup(service))
- .append("_")
- .append(pnp_cleanup(varname))
- .append(".rrd"));
- struct stat st;
- return stat(path.c_str(), &st) == 0 ? path : "";
+ fs::path path =
+ pnp_path / pnp_cleanup(host) /
+ (pnp_cleanup(service) + "_" + pnp_cleanup(varname) +
".rrd");
+ std::error_code ec;
+ fs::status(path, ec);
+ return ec ? "" : path;
}
#endif