| 265 | } |
| 266 | |
| 267 | bool CopyFileX(string const & fOld, string const & fNew) |
| 268 | { |
| 269 | ifstream ifs; |
| 270 | ofstream ofs; |
| 271 | ifs.exceptions(ifstream::failbit | ifstream::badbit); |
| 272 | ofs.exceptions(ifstream::failbit | ifstream::badbit); |
| 273 | |
| 274 | try |
| 275 | { |
| 276 | ifs.open(fOld.c_str()); |
| 277 | ofs.open(fNew.c_str()); |
| 278 | |
| 279 | // If source file is empty - make empty dest file without any errors. |
| 280 | if (IsEOF(ifs)) |
| 281 | return true; |
| 282 | |
| 283 | ofs << ifs.rdbuf(); |
| 284 | ofs.flush(); |
| 285 | return true; |
| 286 | } |
| 287 | catch (system_error const &) |
| 288 | { |
| 289 | LOG(LWARNING, ("Failed to copy file from", fOld, "to", fNew, ":", strerror(errno))); |
| 290 | } |
| 291 | catch (exception const &) |
| 292 | { |
| 293 | LOG(LERROR, ("Unknown error when coping files:", fOld, "to", fNew, strerror(errno))); |
| 294 | } |
| 295 | |
| 296 | // Don't care about possible error here .. |
| 297 | (void)DeleteFileX(fNew); |
| 298 | return false; |
| 299 | } |
| 300 | |
| 301 | bool IsEqualFiles(string const & firstFile, string const & secondFile) |
| 302 | { |