io/FileOutputStream: move code to Delete()

This commit is contained in:
Max Kellermann 2022-05-13 12:22:34 +02:00
parent 270a74e53b
commit bd3e096411
2 changed files with 16 additions and 7 deletions

View File

@ -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
}

View File

@ -205,6 +205,8 @@ private:
return fd.IsDefined();
#endif
}
void Delete(Path delete_path) const noexcept;
};
#endif