diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index 4c928288..7d4377e7 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -808,13 +808,17 @@ public: /** * @brief Sync [mktemp](http://linux.die.net/man/3/mkdtemp). + * * @param tpl Template, as described in the official documentation. - * @return True in case of success, false otherwise. + * + * @return A `std::pair` composed as it follows: + * * A boolean value that is true in case of success, false otherwise. + * * The actual path of the newly created directoy. */ - bool mkdtempSync(std::string tpl) { + std::pair mkdtempSync(std::string tpl) { auto req = get(); cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data()); - return !(req->result < 0); + return std::make_pair(!(req->result < 0), req->path); } /** diff --git a/test/uvw/fs.cpp b/test/uvw/fs.cpp index dcc4e18a..3e118dd5 100644 --- a/test/uvw/fs.cpp +++ b/test/uvw/fs.cpp @@ -535,21 +535,28 @@ TEST(FsReq, MkdirAndRmdirSync) { } -TEST(FsReq, Mkdtemp) { +TEST(FsReq, MkdtempAndRmdir) { const std::string dirname = std::string{TARGET_FS_DIR} + std::string{"/test.dir.XXXXXX"}; auto loop = uvw::Loop::getDefault(); auto request = loop->resource(); bool checkFsMkdtempEvent = false; + bool checkFsRmdirEvent = false; request->on([](const auto &, auto &) { FAIL(); }); - request->on>([&checkFsMkdtempEvent](const auto &, auto &) { + request->on>([&checkFsRmdirEvent](const auto &, auto &) { + ASSERT_FALSE(checkFsRmdirEvent); + checkFsRmdirEvent = true; + }); + + request->on>([&checkFsMkdtempEvent](const auto &event, auto &request) { ASSERT_FALSE(checkFsMkdtempEvent); checkFsMkdtempEvent = true; + request.rmdir(event.path); }); request->mkdtemp(dirname); @@ -557,16 +564,20 @@ TEST(FsReq, Mkdtemp) { loop->run(); ASSERT_TRUE(checkFsMkdtempEvent); + ASSERT_TRUE(checkFsRmdirEvent); } -TEST(FsReq, MkdtempSync) { +TEST(FsReq, MkdtempAndRmdirSync) { const std::string dirname = std::string{TARGET_FS_DIR} + std::string{"/test.dir.XXXXXX"}; auto loop = uvw::Loop::getDefault(); auto request = loop->resource(); - ASSERT_TRUE(request->mkdtempSync(dirname)); + auto mkdtempR = request->mkdtempSync(dirname); + + ASSERT_TRUE(mkdtempR.first); + ASSERT_TRUE(request->rmdirSync(mkdtempR.second)); loop->run(); }