Hi Thien,

Given file_name_find_g = "testme".

Is filter_logfile_name() expected to return true if finfo->d_name = "testme_20200407_143120_20200407_153120.log"?
or finfo->d_name = "testme_2.log.log"?

To me, it is better to use regular expression to assure that it only returns true if finfo->d_name matches the pattern: d_name starts with `file_name_find_g`, then follows by '_yyyyMMdd_HHmmss' time format and ends with '.log' extension|.||

E.g:

|#include <regex>

static std::string file_name_find_g;
static int filter_logfile_name(const struct dirent *finfo) {
    const std::string pattern = "^" + file_name_find_g + "_[0-9]{8}_[0-9]{6}.log$";
    const std::regex e{pattern};
    if (std::regex_match(finfo->d_name, e)) {
        return true;
    }
    return false;
}




On 4/7/20 1:21 PM, thien.m.huynh wrote:
---
  src/log/logd/lgs_filehdl.cc | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/log/logd/lgs_filehdl.cc b/src/log/logd/lgs_filehdl.cc
index 0d7fb2b74..238259454 100644
--- a/src/log/logd/lgs_filehdl.cc
+++ b/src/log/logd/lgs_filehdl.cc
@@ -965,8 +965,10 @@ static int chr_cnt_b(char *str, char c, int lim) {
  static std::string file_name_find_g;
  static int filter_logfile_name(const struct dirent *finfo) {
    int found = 0;
+  int len = file_name_find_g.length();
- if ((strstr(finfo->d_name, file_name_find_g.c_str()) != nullptr) &&
+  if ((strncmp(finfo->d_name, file_name_find_g.c_str(), len) == 0) &&
+      isdigit(finfo->d_name[len + 1]) &&
        (strstr(finfo->d_name, ".log") != nullptr))
      found = 1;


_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to