You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bb...@apache.org on 2021/01/30 01:42:33 UTC

[geode-native] branch develop updated: Geode 8892 loosen log file name rules (#734)

This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5600a6b  Geode 8892 loosen log file name rules (#734)
5600a6b is described below

commit 5600a6b1fc26adddcb8214a9d079ec5627ff1807
Author: Blake Bender <bb...@pivotal.io>
AuthorDate: Fri Jan 29 17:42:23 2021 -0800

    Geode 8892 loosen log file name rules (#734)
    
    - This was breaking some existing users, whose file names were suddenly
      deemed invalid, even though perfectly legal on their platform.
    - Add unit test case for parens and spaces in filename on Windows
    - Add hash symbol to valid filename test.  Turns out these are okay on Windows too
---
 cppcache/src/Log.cpp          | 21 +++++++++------------
 cppcache/test/LoggingTest.cpp |  5 +++++
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/cppcache/src/Log.cpp b/cppcache/src/Log.cpp
index 9e7c15a..aaf71b9 100644
--- a/cppcache/src/Log.cpp
+++ b/cppcache/src/Log.cpp
@@ -102,14 +102,6 @@ void Log::validateSizeLimits(int64_t fileSizeLimit, int64_t diskSpaceLimit) {
   }
 }
 
-void Log::validateLogFileName(const std::string& filename) {
-  auto nameToCheck = boost::filesystem::path(filename).filename().string();
-  if (!boost::filesystem::portable_file_name(nameToCheck)) {
-    throw IllegalArgumentException("Specified log file (" + nameToCheck +
-                                   ") is not a valid portable name.");
-  }
-}
-
 void Log::init(LogLevel level, const char* logFileName, int32_t logFileLimit,
                int64_t logDiskSpaceLimit) {
   auto logFileNameString =
@@ -211,12 +203,11 @@ void Log::init(LogLevel level, const std::string& logFileName,
   }
   s_logLevel = level;
 
-  std::lock_guard<decltype(g_logMutex)> guard(g_logMutex);
+  try {
+    std::lock_guard<decltype(g_logMutex)> guard(g_logMutex);
 
-  g_hostName = boost::asio::ip::host_name();
+    g_hostName = boost::asio::ip::host_name();
 
-  if (logFileName.length()) {
-    validateLogFileName(logFileName);
     g_fullpath =
         boost::filesystem::absolute(boost::filesystem::path(logFileName));
 
@@ -245,6 +236,12 @@ void Log::init(LogLevel level, const std::string& logFileName,
       rollLogFile();
     }
     writeBanner();
+  } catch (const boost::exception&) {
+    auto msg = std::string("Unable to log to file '") + logFileName + "'";
+    throw IllegalArgumentException(msg.c_str());
+  } catch (const std::exception&) {
+    auto msg = std::string("Unable to log to file '") + logFileName + "'";
+    throw IllegalArgumentException(msg.c_str());
   }
 }
 
diff --git a/cppcache/test/LoggingTest.cpp b/cppcache/test/LoggingTest.cpp
index cbeb4d3..ce68ef9 100644
--- a/cppcache/test/LoggingTest.cpp
+++ b/cppcache/test/LoggingTest.cpp
@@ -238,6 +238,11 @@ TEST_F(LoggingTest, logInit) {
       apache::geode::client::LogLevel::Config, "LoggingTest.log"));
   apache::geode::client::Log::close();
 
+  // Init with legal filename with (), #, and space
+  ASSERT_NO_THROW(apache::geode::client::Log::init(
+      apache::geode::client::LogLevel::Config, "LoggingTest (#).log"));
+  apache::geode::client::Log::close();
+
   // Init with invalid filename
   ASSERT_THROW(apache::geode::client::Log::init(
                    apache::geode::client::LogLevel::Config, "#?$?%.log"),