acelyc111 commented on code in PR #1809:
URL:
https://github.com/apache/incubator-pegasus/pull/1809#discussion_r1434912833
##########
src/utils/test/logger.cpp:
##########
@@ -36,99 +37,95 @@
#include "gtest/gtest.h"
#include "utils/api_utilities.h"
-#include "utils/error_code.h"
#include "utils/filesystem.h"
+#include "utils/flags.h"
#include "utils/logging_provider.h"
-#include "utils/ports.h"
#include "utils/safe_strerror_posix.h"
#include "utils/simple_logger.h"
-using std::vector;
-using std::string;
+namespace dsn {
+namespace tools {
-using namespace dsn;
-using namespace dsn::tools;
+DSN_DECLARE_uint64(max_number_of_log_files_on_disk);
-static const int simple_logger_gc_gap = 20;
+namespace {
-static void get_log_file_index(vector<int> &log_index)
+void get_log_file_index(std::vector<int> &log_index)
{
- vector<string> sub_list;
- string path = "./";
- ASSERT_TRUE(utils::filesystem::get_subfiles(path, sub_list, false));
+ std::vector<std::string> sub_list;
+ ASSERT_TRUE(dsn::utils::filesystem::get_subfiles("./", sub_list, false));
- for (auto &ptr : sub_list) {
- auto &&name = utils::filesystem::get_file_name(ptr);
- if (name.length() <= 8 || name.substr(0, 4) != "log.")
+ for (const auto &path : sub_list) {
+ const auto &name = dsn::utils::filesystem::get_file_name(path);
+ if (!boost::algorithm::starts_with(name, "log.")) {
continue;
+ }
+ if (!boost::algorithm::ends_with(name, ".txt")) {
+ continue;
+ }
+
int index;
- if (1 != sscanf(name.c_str(), "log.%d.txt", &index))
+ if (1 != sscanf(name.c_str(), "log.%d.txt", &index)) {
continue;
+ }
log_index.push_back(index);
}
}
-static void clear_files(vector<int> &log_index)
-{
- char file[256] = {};
- for (auto i : log_index) {
- snprintf_p(file, 256, "log.%d.txt", i);
- dsn::utils::filesystem::remove_path(string(file));
- }
-}
+// Don't name the dir with "./test", otherwise the whole utils test dir would
be removed.
Review Comment:
👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]