diff options
author | pogorelov <pogorelov@yandex-team.com> | 2023-08-28 17:03:54 +0300 |
---|---|---|
committer | pogorelov <pogorelov@yandex-team.com> | 2023-08-28 17:38:58 +0300 |
commit | 1e82f33abca18eecf6a334a3a20c81398765b1a2 (patch) | |
tree | cda30780d39e9453cb6176faaba4c318f6dc7fc4 | |
parent | 0d3994e1a90d60e68f14d414d9ff3dde1364c533 (diff) | |
download | ydb-1e82f33abca18eecf6a334a3a20c81398765b1a2.tar.gz |
Fix possible artifacts data corruption
-rw-r--r-- | yt/yt/core/misc/fs.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/yt/yt/core/misc/fs.cpp b/yt/yt/core/misc/fs.cpp index 794e17bc386..440956f273f 100644 --- a/yt/yt/core/misc/fs.cpp +++ b/yt/yt/core/misc/fs.cpp @@ -1061,22 +1061,29 @@ void ReadWriteCopySync( std::vector<ui8> buffer(chunkSize); while (true) { - auto readSize = read(srcFd, buffer.data(), chunkSize); + auto readByteCount = read(srcFd, buffer.data(), chunkSize); - if (readSize == -1) { + if (readByteCount == -1) { THROW_ERROR_EXCEPTION("Error while doing read") << TError::FromSystem(); } - if (readSize == 0) { + if (readByteCount == 0) { return; } - auto size = write(dstFd, buffer.data(), readSize); + for (int writtenByteCount = 0; writtenByteCount < readByteCount;) { + auto byteCount = write( + dstFd, + buffer.data() + writtenByteCount, + readByteCount - writtenByteCount); - if (size == -1) { - THROW_ERROR_EXCEPTION("Error while doing write") - << TError::FromSystem(); + if (byteCount == -1) { + THROW_ERROR_EXCEPTION("Error while doing write") + << TError::FromSystem(); + } + + writtenByteCount += byteCount; } } #else |