From 42464fb72aa590fbc07683719ab9b09009d17fe1 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Tue, 7 Dec 2010 15:47:24 -0800 Subject: [PATCH] logging: Add symlink helper functions Signed-off-by: Colin McCabe --- src/common/DoutStreambuf.cc | 41 ++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index e381a15c9cc90..d7cbf99ba7697 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -116,6 +116,42 @@ static int safe_write(int fd, const char *buf, signed int len) } } +static int create_symlink(const string &oldpath, const string &newpath) +{ + while (1) { + if (::symlink(oldpath.c_str(), newpath.c_str()) == 0) + return 0; + int err = errno; + if (err == EEXIST) { + // Handle EEXIST + if (::unlink(newpath.c_str())) { + err = errno; + ostringstream oss; + oss << __func__ << ": failed to remove '" << newpath << "': " + << cpp_strerror(err) << "\n"; + primitive_log(oss.str()); + return err; + } + } + else { + // Other errors + ostringstream oss; + oss << __func__ << ": failed to symlink(oldpath='" << oldpath + << "', newpath='" << newpath << "'): " << cpp_strerror(err) << "\n"; + primitive_log(oss.str()); + return err; + } + } +} + +static std::string get_basename(const std::string &filename) +{ + size_t last_slash = filename.find_last_of("/"); + if (last_slash == std::string::npos) + return filename; + return filename.substr(last_slash + 1); +} + ///////////////////////////// DoutStreambuf ///////////////////////////// template DoutStreambuf::DoutStreambuf() @@ -376,7 +412,9 @@ bool DoutStreambuf::_read_ofile_config() { opath = _calculate_opath(); if (opath.empty()) { - primitive_log("_calculate_opath failed.\n"); + ostringstream oss; + oss << __func__ << ": _calculate_opath failed.\n"; + primitive_log(oss.str()); return false; } @@ -391,6 +429,7 @@ bool DoutStreambuf::_read_ofile_config() primitive_log(oss.str()); return false; } + return true; } -- 2.39.5