Skip to content

Commit f67f6ff

Browse files
committed
works correctly if project.log doesn't exist yet
1 parent bbe325d commit f67f6ff

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/lib_raColTest/logger.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ void fcat(const char* top_path, const char* bottom_path, const char* output_path
102102
);
103103

104104
char* buff[BUFF_SIZE];
105-
while (fread(buff, sizeof(char), BUFF_SIZE, bottom_file) == BUFF_SIZE) {
106-
fwrite(buff, sizeof(char), BUFF_SIZE, temp_log);
105+
size_t read_size;
106+
do {
107+
read_size = fread(buff, sizeof(char), BUFF_SIZE, bottom_file);
108+
fwrite(buff, sizeof(char), read_size, temp_log);
107109
rCT_sys::error_handler(errno, "Failed to write to temp_cat.log");
108-
}
110+
} while (read_size == BUFF_SIZE);
109111
rCT_sys::error_handler(errno, "Failed to read from project.log");
110112
rCT_sys::fclose_handler( \
111113
fclose(bottom_file), \
@@ -133,11 +135,15 @@ void logger::log(logger::data_type msg_type, const char* test_file, const char*
133135
fclose(line_log), \
134136
line_path \
135137
);
136-
fcat(line_path, log_path, log_path);
137-
rCT_sys::io_handler( \
138-
std::remove(line_path), \
139-
line_path, "Failed to remove " \
140-
);
138+
if (std::filesystem::exists(log_path)) {
139+
fcat(line_path, log_path, log_path);
140+
rCT_sys::io_handler( \
141+
std::remove(line_path), \
142+
line_path, "Failed to remove " \
143+
);
144+
} else {
145+
std::filesystem::rename(line_path, log_path);
146+
}
141147
}
142148

143149
void logger::log_captured_stdout(const char* test_file, const char* test_name, int stdout_cap_fd) {

0 commit comments

Comments
 (0)