libutil: Fix writeFull to respect allowInterrupts
c0e849b696 broke interrupt handling since
writeFull started throwing Interrupted even when allowInterrupts was false.
This would lead to exceptions leaking out when they must not (for example during
progress bar shutdown).
This commit is contained in:
@@ -97,7 +97,7 @@ void writeFull(Descriptor fd, std::string_view s, bool allowInterrupts)
|
||||
if (allowInterrupts)
|
||||
checkInterrupt();
|
||||
auto res = retryOnBlock(fd, PollDirection::Out, [&]() {
|
||||
return write(fd, {reinterpret_cast<const std::byte *>(s.data()), s.size()});
|
||||
return write(fd, {reinterpret_cast<const std::byte *>(s.data()), s.size()}, allowInterrupts);
|
||||
});
|
||||
if (res > 0)
|
||||
s.remove_prefix(res);
|
||||
|
||||
@@ -85,7 +85,7 @@ size_t read(Descriptor fd, std::span<std::byte> buffer);
|
||||
* @return The number of bytes actually written
|
||||
* @throws SystemError on failure
|
||||
*/
|
||||
size_t write(Descriptor fd, std::span<const std::byte> buffer);
|
||||
size_t write(Descriptor fd, std::span<const std::byte> buffer, bool allowInterrupts);
|
||||
|
||||
/**
|
||||
* Get the size of a file.
|
||||
|
||||
@@ -42,11 +42,12 @@ size_t readOffset(Descriptor fd, off_t offset, std::span<std::byte> buffer)
|
||||
return static_cast<size_t>(n);
|
||||
}
|
||||
|
||||
size_t write(Descriptor fd, std::span<const std::byte> buffer)
|
||||
size_t write(Descriptor fd, std::span<const std::byte> buffer, bool allowInterrupts)
|
||||
{
|
||||
ssize_t n;
|
||||
do {
|
||||
checkInterrupt();
|
||||
if (allowInterrupts)
|
||||
checkInterrupt();
|
||||
n = ::write(fd, buffer.data(), buffer.size());
|
||||
} while (n == -1 && errno == EINTR);
|
||||
if (n == -1)
|
||||
|
||||
@@ -60,9 +60,10 @@ size_t readOffset(Descriptor fd, off_t offset, std::span<std::byte> buffer)
|
||||
return static_cast<size_t>(n);
|
||||
}
|
||||
|
||||
size_t write(Descriptor fd, std::span<const std::byte> buffer)
|
||||
size_t write(Descriptor fd, std::span<const std::byte> buffer, bool allowInterrupts)
|
||||
{
|
||||
checkInterrupt(); // For consistency with unix
|
||||
if (allowInterrupts)
|
||||
checkInterrupt(); // For consistency with unix
|
||||
DWORD n;
|
||||
if (!WriteFile(fd, buffer.data(), static_cast<DWORD>(buffer.size()), &n, NULL)) {
|
||||
auto lastError = GetLastError();
|
||||
|
||||
Reference in New Issue
Block a user