MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CopyFile

Function CopyFile

src/base/file_util.h:264–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264__attribute__((unused)) static bool CopyFile(const std::string& src_file,
265 const std::string& desc_file) {
266 if (!IsExists(src_file)) {
267 return false;
268 }
269 FILE* f_src = fopen(src_file.c_str(), "r");
270 if (!f_src) {
271 return false;
272 }
273 FILE* f_desc = fopen(desc_file.c_str(), "w+");
274 if (!f_desc) {
275 fclose(f_src);
276 return false;
277 }
278 char buf[BOLCK_SIZE];
279 bool has_error = false;
280 while (!feof(f_src)) {
281 size_t r_len = fread(buf, sizeof(char), BOLCK_SIZE, f_src);
282 if (r_len < BOLCK_SIZE) {
283 if (!feof(f_src)) {
284 has_error = true;
285 break;
286 }
287 }
288 size_t w_len = fwrite(buf, sizeof(char), r_len, f_desc);
289 if (w_len < r_len) {
290 has_error = true;
291 break;
292 }
293 }
294 fclose(f_src);
295 fclose(f_desc);
296 return has_error == false;
297}
298
299} // namespace base
300} // namespace fedb

Callers 2

SendIndexDataInternalMethod · 0.85
TEST_FFunction · 0.85

Calls 1

IsExistsFunction · 0.85

Tested by 1

TEST_FFunction · 0.68