| 188 | } |
| 189 | |
| 190 | int CopyFile(const string &src_file_path, const string &dst_file_path) { |
| 191 | try { |
| 192 | ifstream src(src_file_path, ios::binary); |
| 193 | ofstream dst(dst_file_path, ios::binary); |
| 194 | if (src.is_open() && dst.is_open() && src.good() && dst.good()) { |
| 195 | dst << src.rdbuf(); |
| 196 | } |
| 197 | if (dst.bad()) { |
| 198 | // if no characters were inserted, executes failbit |
| 199 | // <http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt> |
| 200 | // TODO: |
| 201 | //QLogErr("iofstream \"%s\" -> \"%s\" err", |
| 202 | // src_file_path.c_str(), dst_file_path.c_str()); |
| 203 | |
| 204 | return -1; |
| 205 | } |
| 206 | // TODO: |
| 207 | //QLInfo("iofstream \"%s\" -> \"%s\" ok", src_file_path.c_str(), dst_file_path.c_str()); |
| 208 | } catch(const exception &e) { |
| 209 | // TODO: |
| 210 | //QLErr("iofstream \"%s\" -> \"%s\" e \"%s\"", |
| 211 | // src_file_path.c_str(), dst_file_path.c_str(), e.what()); |
| 212 | |
| 213 | return -1; |
| 214 | } |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | int RemoveDir(const string &dir_path) { |
| 220 | if (-1 == rmdir(dir_path.c_str())) { |