diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-02-27 22:02:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-02-27 22:02:43 +0000 |
commit | 057ee1ae4e3df54e91c146e4adceac34e8c729ef (patch) | |
tree | 9069b319d105a7d417b62bce5080c2ce328ab344 | |
parent | 92aa771c16d2aa1449874ec3906f7441ad3fb2f1 (diff) | |
download | rspamd-057ee1ae4e3df54e91c146e4adceac34e8c729ef.tar.gz rspamd-057ee1ae4e3df54e91c146e4adceac34e8c729ef.zip |
[Minor] Be more consistent about the trailing slash
-rw-r--r-- | src/libutil/cxx/file_util.cxx | 14 | ||||
-rw-r--r-- | 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 { |