aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/util.cpp')
-rw-r--r--src/common/util.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp
index b4f3360ef..ea117dff3 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -121,7 +121,7 @@ namespace tools
private_file::private_file(std::FILE* handle, std::string&& filename) noexcept
: m_handle(handle), m_filename(std::move(filename)) {}
- private_file private_file::create(std::string name)
+ private_file private_file::create(std::string name, uint32_t extra_flags)
{
#ifdef WIN32
struct close_handle
@@ -174,7 +174,7 @@ namespace tools
name.c_str(),
GENERIC_WRITE, FILE_SHARE_READ,
std::addressof(attributes),
- CREATE_NEW, (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE),
+ CREATE_NEW, (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE | extra_flags),
nullptr
)
};
@@ -193,7 +193,7 @@ namespace tools
}
}
#else
- const int fdr = open(name.c_str(), (O_RDONLY | O_CREAT), S_IRUSR);
+ const int fdr = open(name.c_str(), (O_RDONLY | O_CREAT | extra_flags), S_IRUSR);
if (0 <= fdr)
{
struct stat rstats = {};
@@ -224,6 +224,23 @@ namespace tools
return {};
}
+ private_file private_file::drop_and_recreate(std::string filename)
+ {
+ if (epee::file_io_utils::is_file_exist(filename)) {
+ boost::system::error_code ec{};
+ boost::filesystem::remove(filename, ec);
+ if (ec) {
+ MERROR("Failed to remove " << filename << ": " << ec.message());
+ return {};
+ }
+ }
+#ifdef WIN32
+ return create(filename);
+#else
+ return create(filename, O_EXCL);
+#endif
+ }
+
private_file::~private_file() noexcept
{
try