mirror of https://github.com/kiwix/libkiwix.git
in copyFile() try to make a link if possible, copy the content otherwise
This commit is contained in:
parent
b2c38ebfc2
commit
dc60455cd3
|
@ -191,11 +191,18 @@ bool makeDirectory(const string &path) {
|
||||||
return status == 0;
|
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) {
|
bool copyFile(const string &sourcePath, const string &destPath) {
|
||||||
try {
|
try {
|
||||||
std::ifstream infile(sourcePath.c_str(), std::ios_base::binary);
|
#ifndef _WIN32
|
||||||
std::ofstream outfile(destPath.c_str(), std::ios_base::binary);
|
if (link(sourcePath.c_str(), destPath.c_str())) {
|
||||||
outfile << infile.rdbuf();
|
#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) {
|
} catch (exception &e) {
|
||||||
cerr << e.what() << endl;
|
cerr << e.what() << endl;
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue