switch back to boost::filesystem to avoid the requirement of c++17
This commit is contained in:
+13
-10
@@ -6,7 +6,6 @@
|
||||
#include <chrono>
|
||||
#include <cstdarg>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <iomanip> // for put_time
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
@@ -21,6 +20,10 @@
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
namespace webcc {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -33,7 +36,7 @@ static const char* kLevelNames[] = {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static FILE* FOpen(const std::filesystem::path& path, bool overwrite) {
|
||||
static FILE* FOpen(const bfs::path& path, bool overwrite) {
|
||||
#if (defined(_WIN32) || defined(_WIN64))
|
||||
return _wfopen(path.wstring().c_str(), overwrite ? L"w+" : L"a+");
|
||||
#else
|
||||
@@ -45,7 +48,7 @@ struct Logger {
|
||||
Logger() : file(nullptr), modes(0) {
|
||||
}
|
||||
|
||||
void Init(const std::filesystem::path& path, int _modes) {
|
||||
void Init(const bfs::path& path, int _modes) {
|
||||
modes = _modes;
|
||||
|
||||
// Create log file only if necessary.
|
||||
@@ -153,22 +156,22 @@ static std::string GetThreadID() {
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
static std::filesystem::path InitLogPath(const std::filesystem::path& dir) {
|
||||
static bfs::path InitLogPath(const bfs::path& dir) {
|
||||
if (dir.empty()) {
|
||||
return std::filesystem::current_path() / WEBCC_LOG_FILE_NAME;
|
||||
return bfs::current_path() / WEBCC_LOG_FILE_NAME;
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) {
|
||||
std::error_code ec;
|
||||
if (!std::filesystem::create_directories(dir, ec) || ec) {
|
||||
return std::filesystem::path{};
|
||||
if (!bfs::exists(dir) || !bfs::is_directory(dir)) {
|
||||
boost::system::error_code ec;
|
||||
if (!bfs::create_directories(dir, ec) || ec) {
|
||||
return bfs::path{};
|
||||
}
|
||||
}
|
||||
|
||||
return (dir / WEBCC_LOG_FILE_NAME);
|
||||
}
|
||||
|
||||
void LogInit(const std::filesystem::path& dir, int modes) {
|
||||
void LogInit(const bfs::path& dir, int modes) {
|
||||
// Suppose this is called from the main thread.
|
||||
g_main_thread_id = DoGetThreadID();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user