commit 057ee1a: [Minor] Be more consistent about the trailing slash
Vsevolod Stakhov
vsevolod at rspamd.com
Mon Feb 27 22:07:04 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-02-27 22:02:43 +0000
URL: https://github.com/rspamd/rspamd/commit/057ee1ae4e3df54e91c146e4adceac34e8c729ef (HEAD -> master)
[Minor] Be more consistent about the trailing slash
---
src/libutil/cxx/file_util.cxx | 14 ++++++++++++--
src/libutil/cxx/file_util.hxx | 2 +-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/libutil/cxx/file_util.cxx b/src/libutil/cxx/file_util.cxx
index e5286a2cd..317683370 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 06073dbab..e712fcb15 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 {
More information about the Commits
mailing list