From: Vsevolod Stakhov Date: Mon, 27 Feb 2023 22:02:43 +0000 (+0000) Subject: [Minor] Be more consistent about the trailing slash X-Git-Tag: 3.5~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=057ee1ae4e3df54e91c146e4adceac34e8c729ef;p=thirdparty%2Frspamd.git [Minor] Be more consistent about the trailing slash --- diff --git a/src/libutil/cxx/file_util.cxx b/src/libutil/cxx/file_util.cxx index e5286a2cde..3176833705 100644 --- a/src/libutil/cxx/file_util.cxx +++ b/src/libutil/cxx/file_util.cxx @@ -368,12 +368,22 @@ TEST_CASE("check lock") { CHECK(serrno == ENOENT); } -auto get_tmpdir() -> const char * { +auto get_tmpdir() -> std::string { const auto *tmpdir = getenv("TMPDIR"); if (tmpdir == nullptr) { tmpdir = G_DIR_SEPARATOR_S "tmp"; } - return tmpdir; + + std::size_t sz; + std::string mut_fname = tmpdir; + rspamd_normalize_path_inplace(mut_fname.data(), mut_fname.size(), &sz); + mut_fname.resize(sz); + + if (!mut_fname.ends_with(G_DIR_SEPARATOR)) { + mut_fname += G_DIR_SEPARATOR; + } + + return mut_fname; } TEST_CASE("tempfile") { diff --git a/src/libutil/cxx/file_util.hxx b/src/libutil/cxx/file_util.hxx index 06073dbab8..e712fcb15f 100644 --- a/src/libutil/cxx/file_util.hxx +++ b/src/libutil/cxx/file_util.hxx @@ -64,7 +64,7 @@ public: sep_pos --; } - return std::string_view{fname.c_str(), sep_pos}; + return std::string_view{fname.c_str(), sep_pos + 1}; } auto get_extension() const -> std::string_view {