From dc60455cd38cddb2312845c3cb08524301b038a5 Mon Sep 17 00:00:00 2001 From: Emmanuel Engelhart Date: Sat, 21 Feb 2015 16:56:38 +0100 Subject: [PATCH] in copyFile() try to make a link if possible, copy the content otherwise --- src/common/pathTools.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/common/pathTools.cpp b/src/common/pathTools.cpp index 274953877..1e8c414b1 100644 --- a/src/common/pathTools.cpp +++ b/src/common/pathTools.cpp @@ -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;