mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-24 06:32:06 +08:00
refactoed file_helper
This commit is contained in:
parent
49eb9cbdd8
commit
0c60107e62
@ -28,15 +28,14 @@ SPDLOG_INLINE file_helper::~file_helper()
|
|||||||
SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab");
|
|
||||||
auto folder_name = os::dir_name(fname);
|
|
||||||
filename_ = fname;
|
filename_ = fname;
|
||||||
|
|
||||||
|
// create containing folder if not empty string and not exists already
|
||||||
|
os::create_dir(os::dir_name(fname));
|
||||||
|
|
||||||
|
auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab");
|
||||||
for (int tries = 0; tries < open_tries_; ++tries)
|
for (int tries = 0; tries < open_tries_; ++tries)
|
||||||
{
|
{
|
||||||
// create if not empty and not exists already
|
|
||||||
os::create_dir(folder_name);
|
|
||||||
|
|
||||||
if (!os::fopen_s(&fd_, fname, mode))
|
if (!os::fopen_s(&fd_, fname, mode))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -499,6 +499,7 @@ SPDLOG_INLINE bool create_dir(filename_t path)
|
|||||||
size_t search_offset = 0;
|
size_t search_offset = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
fmt::string_view t;
|
||||||
auto token_pos = path.find(folder_sep, search_offset);
|
auto token_pos = path.find(folder_sep, search_offset);
|
||||||
// treat the entire path as a folder if no folder separator not found
|
// treat the entire path as a folder if no folder separator not found
|
||||||
if (token_pos == filename_t::npos)
|
if (token_pos == filename_t::npos)
|
||||||
|
Loading…
Reference in New Issue
Block a user