Skip to content

Commit 48ed3ef

Browse files
joyeecheungQard
andauthored
fixup! src: consolidate C++ ReadFileSync/WriteFileSync utilities
Co-authored-by: Stephen Belanger <admin@stephenbelanger.com>
1 parent 0ae8c1a commit 48ed3ef

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/node_file_utils.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ int WriteFileSync(const char* path, uv_buf_t* bufs, size_t buf_count) {
4545

4646
while (idx < iovs.size()) {
4747
// Skip empty buffers.
48-
while (idx < iovs.size() && iovs[idx].len == 0) {
48+
if (iovs[idx].len == 0) {
4949
idx++;
50-
}
51-
if (idx >= iovs.size()) { // No non-empty buffers left.
52-
break;
50+
continue;
5351
}
5452

5553
uv_fs_write(nullptr,
@@ -59,19 +57,14 @@ int WriteFileSync(const char* path, uv_buf_t* bufs, size_t buf_count) {
5957
iovs.size() - idx,
6058
kCurrentFileOffset,
6159
nullptr);
62-
if (req.result < 0) { // Error during write.
63-
int err = req.result;
60+
if (req.result <= 0) { // Error during write.
61+
// UV_EIO should not happen unless the file system is full.
62+
int err = req.result < 0 ? req.result : UV_EIO;
6463
uv_fs_req_cleanup(&req);
6564
uv_fs_close(nullptr, &req, fd, nullptr);
6665
uv_fs_req_cleanup(&req);
6766
return err;
6867
}
69-
if (req.result == 0) { // Should not happen unless the file system is full.
70-
uv_fs_req_cleanup(&req);
71-
uv_fs_close(nullptr, &req, fd, nullptr);
72-
uv_fs_req_cleanup(&req);
73-
return UV_EIO;
74-
}
7568
size_t written = req.result;
7669
uv_fs_req_cleanup(&req);
7770

0 commit comments

Comments
 (0)