From bd3e09641162d106d1495a7dd2e0152fd8456d2d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 13 May 2022 12:22:34 +0200 Subject: [PATCH] io/FileOutputStream: move code to Delete() --- src/io/FileOutputStream.cxx | 21 ++++++++++++++------- src/io/FileOutputStream.hxx | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/io/FileOutputStream.cxx b/src/io/FileOutputStream.cxx index cc0284658..939586ebf 100644 --- a/src/io/FileOutputStream.cxx +++ b/src/io/FileOutputStream.cxx @@ -296,13 +296,7 @@ FileOutputStream::Cancel() noexcept #ifdef HAVE_O_TMPFILE if (!is_tmpfile) #endif -#ifdef __linux__ - unlinkat(directory_fd.Get(), GetPath().c_str(), 0); -#elif _WIN32 - DeleteFile(GetPath().c_str()); -#else - unlink(GetPath().c_str()); -#endif + Delete(GetPath()); break; case Mode::CREATE_VISIBLE: @@ -313,3 +307,16 @@ FileOutputStream::Cancel() noexcept } } +inline void +FileOutputStream::Delete(Path delete_path) const noexcept +{ + assert(delete_path != nullptr); + +#ifdef _WIN32 + DeleteFile(delete_path.c_str()); +#elif defined(__linux__) + unlinkat(directory_fd.Get(), delete_path.c_str(), 0); +#else + unlink(delete_path.c_str()); +#endif +} diff --git a/src/io/FileOutputStream.hxx b/src/io/FileOutputStream.hxx index 9b36b9ee4..e89d03480 100644 --- a/src/io/FileOutputStream.hxx +++ b/src/io/FileOutputStream.hxx @@ -205,6 +205,8 @@ private: return fd.IsDefined(); #endif } + + void Delete(Path delete_path) const noexcept; }; #endif