You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ab...@apache.org on 2019/06/27 16:45:06 UTC
[nifi-minifi-cpp] branch master updated: MINIFICPP-935 - Remove
_stat to stat defines
This is an automated email from the ASF dual-hosted git repository.
aboda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new 90dc05d MINIFICPP-935 - Remove _stat to stat defines
90dc05d is described below
commit 90dc05d2f288eb1373e2655f0cc8c420061c7e25
Author: Daniel Bakai <ba...@gmail.com>
AuthorDate: Wed Jun 26 18:03:18 2019 +0200
MINIFICPP-935 - Remove _stat to stat defines
Signed-off-by: Arpad Boda <ab...@apache.org>
This closes #599.
---
libminifi/include/utils/file/DiffUtils.h | 4 ----
libminifi/include/utils/file/FileManager.h | 10 +++++----
libminifi/include/utils/file/FileUtils.h | 26 +++++++++++++++-------
libminifi/src/core/logging/LoggerConfiguration.cpp | 6 ++---
libminifi/test/unit/FileUtilsTests.cpp | 1 -
5 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/libminifi/include/utils/file/DiffUtils.h b/libminifi/include/utils/file/DiffUtils.h
index 313e0f6..74e5ef7 100644
--- a/libminifi/include/utils/file/DiffUtils.h
+++ b/libminifi/include/utils/file/DiffUtils.h
@@ -23,13 +23,9 @@
#include <boost/filesystem.hpp>
#else
#include <cstdlib>
-#include <sys/stat.h>
#endif
#include <cstdio>
#include <fcntl.h>
-#ifdef WIN32
-#define stat _stat
-#endif
#ifdef BDIFF
diff --git a/libminifi/include/utils/file/FileManager.h b/libminifi/include/utils/file/FileManager.h
index 22c8302..3babf6b 100644
--- a/libminifi/include/utils/file/FileManager.h
+++ b/libminifi/include/utils/file/FileManager.h
@@ -27,9 +27,6 @@
#include "io/validation.h"
#include "utils/Id.h"
#include "utils/StringUtils.h"
-#ifdef WIN32
-#define stat _stat
-#endif
#ifndef FILE_SEPARATOR
#ifdef WIN32
@@ -115,8 +112,13 @@ class FileManager {
protected:
inline bool verify_not_exist(const std::string& name) {
+#ifdef WIN32
+ struct _stat buffer;
+ return _stat(name.c_str(), &buffer) != 0;
+#else
struct stat buffer;
- return (stat(name.c_str(), &buffer) != 0);
+ return stat(name.c_str(), &buffer) != 0;
+#endif
}
utils::NonRepeatingStringGenerator non_repeating_string_generator_;
diff --git a/libminifi/include/utils/file/FileUtils.h b/libminifi/include/utils/file/FileUtils.h
index 0b000ed..3267321 100644
--- a/libminifi/include/utils/file/FileUtils.h
+++ b/libminifi/include/utils/file/FileUtils.h
@@ -44,7 +44,6 @@
#endif
#include <fcntl.h>
#ifdef WIN32
-#define stat _stat
#include <direct.h>
#include <windows.h> // winapi
#include <sys/stat.h> // stat
@@ -198,11 +197,18 @@ class FileUtils {
#ifdef BOOST_VERSION
return boost::filesystem::last_write_time(movedFile.str());
#else
+#ifdef WIN32
+ struct _stat result;
+ if (_stat(path.c_str(), &result) == 0) {
+ return result.st_mtime;
+ }
+#else
struct stat result;
if (stat(path.c_str(), &result) == 0) {
return result.st_mtime;
}
#endif
+#endif
return 0;
}
@@ -255,17 +261,21 @@ class FileUtils {
return -1;
}
#else
- struct stat dir_stat;
- if (stat(path.c_str(), &dir_stat)) {
#ifdef WIN32
+ struct _stat dir_stat;
+ if (_stat(path.c_str(), &dir_stat)) {
_mkdir(path.c_str());
+ return 0;
+ }
#else
+ struct stat dir_stat;
+ if (stat(path.c_str(), &dir_stat)) {
if (mkdir(path.c_str(), 0700) != 0 && errno != EEXIST) {
return -1;
}
-#endif
return 0;
}
+#endif
return -1;
#endif
}
@@ -336,11 +346,11 @@ class FileUtils {
std::string pathToSearch = originalPath + "\\*" + extension;
if ((hFind = FindFirstFileA(pathToSearch.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE) {
do {
- struct stat statbuf {};
+ struct _stat statbuf {};
std::string path = originalPath + "\\" + FindFileData.cFileName;
logger->log_info("Adding %s to paths", path);
- if (stat(path.c_str(), &statbuf) != 0) {
+ if (_stat(path.c_str(), &statbuf) != 0) {
logger->log_warn("Failed to stat %s", path);
break;
}
@@ -413,10 +423,10 @@ class FileUtils {
}
do {
- struct stat statbuf {};
+ struct _stat statbuf {};
if (strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0) {
std::string path = dir + get_separator() + FindFileData.cFileName;
- if (stat(path.c_str(), &statbuf) != 0) {
+ if (_stat(path.c_str(), &statbuf) != 0) {
logger->log_warn("Failed to stat %s", path);
continue;
}
diff --git a/libminifi/src/core/logging/LoggerConfiguration.cpp b/libminifi/src/core/logging/LoggerConfiguration.cpp
index ef5be53..27db9e6 100644
--- a/libminifi/src/core/logging/LoggerConfiguration.cpp
+++ b/libminifi/src/core/logging/LoggerConfiguration.cpp
@@ -34,7 +34,6 @@
#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/sinks/null_sink.h"
#ifdef WIN32
-#define stat _stat
#include <direct.h>
#define _WINSOCKAPI_
#include <windows.h>
@@ -125,13 +124,14 @@ std::shared_ptr<internal::LoggerNamespace> LoggerConfiguration::initialize_names
if (!directory.empty()) {
// Create the log directory if needed
directory += "/logs";
- struct stat logDirStat;
#ifdef WIN32
- if (stat(directory.c_str(), &logDirStat) != 0) {
+ struct _stat logDirStat;
+ if (_stat(directory.c_str(), &logDirStat) != 0) {
if (_mkdir(directory.c_str()) == -1) {
exit(1);
}
#else
+ struct stat logDirStat;
if (stat(directory.c_str(), &logDirStat) != 0 || !S_ISDIR(logDirStat.st_mode)) {
if (mkdir(directory.c_str(), 0777) == -1) {
exit(1);
diff --git a/libminifi/test/unit/FileUtilsTests.cpp b/libminifi/test/unit/FileUtilsTests.cpp
index 0abd3f6..d40ae99 100644
--- a/libminifi/test/unit/FileUtilsTests.cpp
+++ b/libminifi/test/unit/FileUtilsTests.cpp
@@ -113,7 +113,6 @@ SECTION("FILE NO PATH") {
SECTION("NO FILE NO PATH") {
std::string path = "file";
std::string filename, filepath;
- std::string expectedPath = "" + FileUtils::get_separator();
REQUIRE(false == utils::file::PathUtils::getFileNameAndPath(path, filepath, filename) );
REQUIRE(filepath.empty());
REQUIRE(filename.empty());