[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-17 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367275409
 
 

 ##
 File path: libminifi/src/utils/file/PathUtils.cpp
 ##
 @@ -48,6 +56,35 @@ bool PathUtils::getFileNameAndPath(const std::string , 
std::string 
   return true;
 }
 
+std::string PathUtils::getFullPath(const std::string& path) {
+#ifdef WIN32
+  std::vector buffer(MAX_PATH);
+  uint32_t len = 0U;
+  while (true) {
+  len = GetFullPathNameA(path.c_str(), buffer.size(), buffer.data(), 
nullptr /*lpFilePart*/);
 
 Review comment:
   nit - - can be used GetFullPathName.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-17 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367268406
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
+#else
+int ret = unsetenv(name);
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+std::string Environment::getCurrentWorkingDirectory() {
+  std::string cwd;
+
+  Environment::accessEnvironment([](){
+#ifdef WIN32
+uint32_t len = 0U;
+std::vector buffer;
+// 
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
+// "If the buffer that is pointed to by lpBuffer is not large enough,
+// the return value specifies the required size of the buffer,
+// in characters, including the null-terminating character."
+while (true) {
+  len = GetCurrentDirectoryA(buffer.size(), buffer.data());
+  if (len > buffer.size()) {
+buffer.resize(len);
+continue;
+  } else {
+break;
+  }
+}
+if (len > 0U) {
+  cwd = std::string(buffer.data(), len);
+}
+#else
+std::vector buffer(1024U);
+char* path = nullptr;
+while (true) {
+  path = getcwd(buffer.data(), buffer.size());
+  if (path == nullptr) {
+if (errno == ERANGE) {
+  buffer.resize(buffer.size() * 2);
+  continue;
+} else {
+  break;
+}
+  } else {
+break;
+  }
+}
+if (path != nullptr) {
+  cwd = path;
+}
+#endif
+  });
+
+  return cwd;
+}
+
+bool Environment::setCurrentWorkingDirectory(const char* directory) {
+  bool success = false;
+
+  Environment::accessEnvironment([, directory](){
+#ifdef WIN32
+success = SetCurrentDirectoryA(directory);
 
 Review comment:
   nit - can be used SetCurrentDirectory.


This is 

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-17 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367268047
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
 
 Review comment:
   nit - can used SetEnvironmentVariable.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-17 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367267981
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
 
 Review comment:
   nit - can used SetEnvironmentVariable.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-17 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367268177
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
+#else
+int ret = unsetenv(name);
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+std::string Environment::getCurrentWorkingDirectory() {
+  std::string cwd;
+
+  Environment::accessEnvironment([](){
+#ifdef WIN32
+uint32_t len = 0U;
+std::vector buffer;
+// 
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
+// "If the buffer that is pointed to by lpBuffer is not large enough,
+// the return value specifies the required size of the buffer,
+// in characters, including the null-terminating character."
+while (true) {
+  len = GetCurrentDirectoryA(buffer.size(), buffer.data());
 
 Review comment:
   nit - can be used GetCurrentDirectory.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-16 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367273019
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
+#else
+int ret = unsetenv(name);
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+std::string Environment::getCurrentWorkingDirectory() {
+  std::string cwd;
+
+  Environment::accessEnvironment([](){
+#ifdef WIN32
+uint32_t len = 0U;
 
 Review comment:
   This works, but simpler would be:
   char dir[MAX_PATH+1] ;
   GetCurrentDirectory( sizeof(dir), dir ) ;
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367275409
 
 

 ##
 File path: libminifi/src/utils/file/PathUtils.cpp
 ##
 @@ -48,6 +56,35 @@ bool PathUtils::getFileNameAndPath(const std::string , 
std::string 
   return true;
 }
 
+std::string PathUtils::getFullPath(const std::string& path) {
+#ifdef WIN32
+  std::vector buffer(MAX_PATH);
+  uint32_t len = 0U;
+  while (true) {
+  len = GetFullPathNameA(path.c_str(), buffer.size(), buffer.data(), 
nullptr /*lpFilePart*/);
 
 Review comment:
   nit - - can be used GetFullPathName.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367274461
 
 

 ##
 File path: libminifi/src/utils/file/PathUtils.cpp
 ##
 @@ -48,6 +56,35 @@ bool PathUtils::getFileNameAndPath(const std::string , 
std::string 
   return true;
 }
 
+std::string PathUtils::getFullPath(const std::string& path) {
+#ifdef WIN32
+  std::vector buffer(MAX_PATH);
 
 Review comment:
   MAX_PATH just 260, could be used `char buffer[MAX_PATH+1];`


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367274461
 
 

 ##
 File path: libminifi/src/utils/file/PathUtils.cpp
 ##
 @@ -48,6 +56,35 @@ bool PathUtils::getFileNameAndPath(const std::string , 
std::string 
   return true;
 }
 
+std::string PathUtils::getFullPath(const std::string& path) {
+#ifdef WIN32
+  std::vector buffer(MAX_PATH);
 
 Review comment:
   MAX_PATH just 260, could be used `char buffer[MAX_PATH+1];`


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367273019
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
+#else
+int ret = unsetenv(name);
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+std::string Environment::getCurrentWorkingDirectory() {
+  std::string cwd;
+
+  Environment::accessEnvironment([](){
+#ifdef WIN32
+uint32_t len = 0U;
 
 Review comment:
   This works, but simpler would be:
   char dir[MAX_PATH+1] ;
   GetCurrentDirectory( sizeof(dir), dir ) ;
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367268406
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
+#else
+int ret = unsetenv(name);
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+std::string Environment::getCurrentWorkingDirectory() {
+  std::string cwd;
+
+  Environment::accessEnvironment([](){
+#ifdef WIN32
+uint32_t len = 0U;
+std::vector buffer;
+// 
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
+// "If the buffer that is pointed to by lpBuffer is not large enough,
+// the return value specifies the required size of the buffer,
+// in characters, including the null-terminating character."
+while (true) {
+  len = GetCurrentDirectoryA(buffer.size(), buffer.data());
+  if (len > buffer.size()) {
+buffer.resize(len);
+continue;
+  } else {
+break;
+  }
+}
+if (len > 0U) {
+  cwd = std::string(buffer.data(), len);
+}
+#else
+std::vector buffer(1024U);
+char* path = nullptr;
+while (true) {
+  path = getcwd(buffer.data(), buffer.size());
+  if (path == nullptr) {
+if (errno == ERANGE) {
+  buffer.resize(buffer.size() * 2);
+  continue;
+} else {
+  break;
+}
+  } else {
+break;
+  }
+}
+if (path != nullptr) {
+  cwd = path;
+}
+#endif
+  });
+
+  return cwd;
+}
+
+bool Environment::setCurrentWorkingDirectory(const char* directory) {
+  bool success = false;
+
+  Environment::accessEnvironment([, directory](){
+#ifdef WIN32
+success = SetCurrentDirectoryA(directory);
 
 Review comment:
   nit - can be used SetCurrentDirectory.


This is 

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367268047
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
 
 Review comment:
   nit - can used SetEnvironmentVariable.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367268177
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
+}
+#else
+int ret = setenv(name, value, static_cast(overwrite));
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+bool Environment::unsetEnvironmentVariable(const char* name) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name](){
+#ifdef WIN32
+success = SetEnvironmentVariableA(name, nullptr);
+#else
+int ret = unsetenv(name);
+success = ret == 0;
+#endif
+  });
+
+  return success;
+}
+
+std::string Environment::getCurrentWorkingDirectory() {
+  std::string cwd;
+
+  Environment::accessEnvironment([](){
+#ifdef WIN32
+uint32_t len = 0U;
+std::vector buffer;
+// 
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
+// "If the buffer that is pointed to by lpBuffer is not large enough,
+// the return value specifies the required size of the buffer,
+// in characters, including the null-terminating character."
+while (true) {
+  len = GetCurrentDirectoryA(buffer.size(), buffer.data());
 
 Review comment:
   nit - can be used GetCurrentDirectory.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367267981
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
+if (ret > 0U) {
+  exists = true;
+  value = std::string(buffer.data(), ret);
+} else if (GetLastError() == ERROR_SUCCESS) {
+  // Exists, but empty
+  exists = true;
+}
+#else
+char* ret = getenv(name);
+if (ret != nullptr) {
+  exists = true;
+  value = ret;
+}
+#endif
+  });
+
+  return std::make_pair(exists, std::move(value));
+}
+
+bool Environment::setEnvironmentVariable(const char* name, const char* value, 
bool overwrite /*= true*/) {
+  bool success = false;
+
+  Environment::accessEnvironment([, name, value, overwrite](){
+#ifdef WIN32
+if (!overwrite && Environment::getEnvironmentVariable(name).first) {
+  success = true;
+} else {
+  success = SetEnvironmentVariableA(name, value);
 
 Review comment:
   nit - can used SetEnvironmentVariable.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up minifiexe and MINIFI_HOME logic

2020-01-15 Thread GitBox
am-c-p-p commented on a change in pull request #709: MINIFICPP-1088 - clean up 
minifiexe and MINIFI_HOME logic
URL: https://github.com/apache/nifi-minifi-cpp/pull/709#discussion_r367267576
 
 

 ##
 File path: libminifi/src/utils/Environment.cpp
 ##
 @@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Environment.h"
+
+#ifdef WIN32
+#include 
+#else
+#include 
+#include 
+#include 
+#endif
+#include 
+#include 
+#include 
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+bool Environment::runningAsService_(false);
+
+void Environment::accessEnvironment(const std::function& func) {
+  static std::recursive_mutex environmentMutex;
+  std::lock_guard lock(environmentMutex);
+  func();
+}
+
+std::pair Environment::getEnvironmentVariable(const char* 
name) {
+  bool exists = false;
+  std::string value;
+
+  Environment::accessEnvironment([, , name](){
+#ifdef WIN32
+std::vector buffer(32767U);  // 
https://docs.microsoft.com/en-gb/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea
+// GetEnvironmentVariableA does not set last error to 0 on success, so an 
error from a pervious API call would influence the GetLastError() later,
+// so we set the last error to 0 before calling
+SetLastError(ERROR_SUCCESS);
+uint32_t ret = GetEnvironmentVariableA(name, buffer.data(), buffer.size());
 
 Review comment:
   nit - can be used GetEnvironmentVariable.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services