Skip to content

Commit

Permalink
add symlink directory test for FileSink
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Jun 13, 2024
1 parent 880a696 commit 5ad7bb5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
11 changes: 0 additions & 11 deletions quill/include/quill/sinks/FileSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,6 @@ class FileSink : public StreamSink
_file_event_notifier.before_open(filename);
}

if (!filename.parent_path().empty())
{
std::error_code ec;
fs::create_directories(filename.parent_path(), ec);
if (ec)
{
QUILL_THROW(QuillError{std::string{"create directories failed path: "} +
filename.parent_path().string() + " error: " + ec.message()});
}
}

_file = fopen(filename.string().data(), mode.data());

if (!_file)
Expand Down
39 changes: 39 additions & 0 deletions quill/test/unit_tests/FileSinkTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,43 @@ TEST_CASE("create_directory")
testing::remove_file(filename);
}

#if !defined(_WIN32)
// Symlink test, currently for Linux only but can probably also expanded to windows later

/***/
TEST_CASE("use_symlink_directory")
{
fs::path const target_folder = "./use_symlink_directory_actual";
fs::path const symlink_folder = "./use_symlink_directory_symlink_log";

std::error_code ec;

// create target folder
fs::create_directories(target_folder, ec);
REQUIRE_FALSE(ec);

// Create the symlink
fs::create_symlink(target_folder, symlink_folder, ec);
REQUIRE_FALSE(ec);

REQUIRE(fs::exists(target_folder));
REQUIRE(fs::exists(symlink_folder));

fs::path const filename = symlink_folder / fs::path{"use_symlink_directory.log"};

FileSinkConfig fsc;
fsc.set_filename_append_option(FilenameAppendOption::None);

{
FileSink file_sink{filename, fsc, FileEventNotifier{}, true};
REQUIRE(fs::exists(filename));
}

// Cleanup the symlink after tests
testing::remove_file(filename);
fs::remove(target_folder, ec);
fs::remove(symlink_folder, ec);
}
#endif

TEST_SUITE_END();

0 comments on commit 5ad7bb5

Please sign in to comment.