in copyFile() try to make a link if possible, copy the content otherwise

This commit is contained in:
Emmanuel Engelhart 2015-02-21 16:56:38 +01:00
parent b2c38ebfc2
commit dc60455cd3
1 changed files with 10 additions and 3 deletions

View File

@ -191,11 +191,18 @@ bool makeDirectory(const string &path) {
return status == 0;
}
/* Try to create a link and if does not work then make a copy */
bool copyFile(const string &sourcePath, const string &destPath) {
try {
std::ifstream infile(sourcePath.c_str(), std::ios_base::binary);
std::ofstream outfile(destPath.c_str(), std::ios_base::binary);
outfile << infile.rdbuf();
#ifndef _WIN32
if (link(sourcePath.c_str(), destPath.c_str())) {
#endif
std::ifstream infile(sourcePath.c_str(), std::ios_base::binary);
std::ofstream outfile(destPath.c_str(), std::ios_base::binary);
outfile << infile.rdbuf();
#ifndef _WIN32
}
#endif
} catch (exception &e) {
cerr << e.what() << endl;
return false;