Skip to content

Commit b8b46fa

Browse files
committed
intercept: file writing needs to loop on content until it gets empty
1 parent fbbf540 commit b8b46fa

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

source/intercept/source/collect/db/EventsDatabaseWriter.cc

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,23 @@ namespace ic::collect::db {
8989
return rust::Ok(std::move(json));
9090
}
9191

92-
rust::Result<int> EventsDatabaseWriter::write_to_file(const std::string &content) noexcept {
93-
if (-1 == write(file_, content.c_str(), content.size())) {
94-
auto message = fmt::format(
95-
"Events db write failed (to file {}): {}",
96-
path_.string(),
97-
sys::error_string(errno)
98-
);
99-
errno = 0;
100-
return rust::Result<int>(rust::Err(std::runtime_error(message)));
92+
rust::Result<int> EventsDatabaseWriter::write_to_file(const std::string& content) noexcept {
93+
const char* content_ptr = content.c_str();
94+
size_t content_length = content.size();
95+
while (content_length) {
96+
const int written_length = write(file_, content_ptr, content_length);
97+
if (written_length == -1) {
98+
auto message = fmt::format(
99+
"Events db write failed (to file {}): {}",
100+
path_.string(),
101+
sys::error_string(errno)
102+
);
103+
errno = 0;
104+
return rust::Err(std::runtime_error(message));
105+
}
106+
content_length -= written_length;
107+
content_ptr += written_length;
101108
}
102-
return rust::Result<int>(rust::Ok(1));
109+
return rust::Ok(1);
103110
}
104111
}

0 commit comments

Comments
 (0)