MCPcopy Create free account
hub / github.com/acl-dev/acl / copy_file

Function copy_file

lib_acl_cpp/samples/dircopy/main.cpp:26–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24} while (0)
25
26static bool copy_file(acl::ifstream& in, const acl::string& to_path,
27 const acl::string& to_filepath, int* ncopied)
28{
29 if (in.fseek(0, SEEK_SET) < 0)
30 {
31 logger_error("fseek from file: %s error: %s",
32 in.file_path(), acl::last_serror());
33 return false;
34 }
35
36 if (access(to_path.c_str(), 0) != 0)
37 {
38 if (acl_make_dirs(to_path.c_str(), 0755) == -1)
39 {
40 logger_error("create dirs: %s error: %s",
41 to_path.c_str(), acl::last_serror());
42 return false;
43 }
44 }
45
46 acl_int64 length = in.fsize();
47 if (length < 0)
48 {
49 logger_error("get file(%s)'s size error: %s", in.file_path(),
50 acl::last_serror());
51 return false;
52 }
53
54 acl::ofstream out;
55
56 if (out.open_trunc(to_filepath.c_str()) == false)
57 {
58 logger_error("ope_trunc file: %s error: %s",
59 to_filepath.c_str(), acl::last_serror());
60 return false;
61 }
62
63 logger("copying from file: %s, to file: %s", in.file_path(),
64 to_filepath.c_str());
65
66 char buf[4096];
67 int ret;
68 acl_int64 nread = 0;
69
70 while (true)
71 {
72 ret = in.read(buf, sizeof(buf), false);
73 if (ret == -1)
74 {
75 if (nread == length)
76 break;
77
78 logger_error("read from file: %s error: %s, "
79 "to file: %s, nread: %lld, length: %lld",
80 in.file_path(), acl::last_serror(),
81 to_filepath.c_str(), nread, length);
82 return false;
83 }

Callers 1

cmp_copyFunction · 0.70

Calls 9

acl_make_dirsFunction · 0.85
fseekMethod · 0.80
file_pathMethod · 0.80
fsizeMethod · 0.80
last_serrorFunction · 0.50
c_strMethod · 0.45
open_truncMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…