Skip to content
Snippets Groups Projects
Commit dd703ac6 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

SystemTools: make file copying mechanisms public

CMake will use these in its own file copying routines (which will
capture errors).
parent e359c1e4
No related branches found
No related tags found
No related merge requests found
...@@ -2273,11 +2273,8 @@ bool SystemTools::TextFilesDiffer(const std::string& path1, ...@@ -2273,11 +2273,8 @@ bool SystemTools::TextFilesDiffer(const std::string& path1,
return false; return false;
} }
/** bool SystemTools::CopyFileContentBlockwise(const std::string& source,
* Blockwise copy source to destination file const std::string& destination)
*/
static bool CopyFileContentBlockwise(const std::string& source,
const std::string& destination)
{ {
// Open files // Open files
kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary); kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary);
...@@ -2341,8 +2338,8 @@ static bool CopyFileContentBlockwise(const std::string& source, ...@@ -2341,8 +2338,8 @@ static bool CopyFileContentBlockwise(const std::string& source,
* - The underlying filesystem does not support file cloning * - The underlying filesystem does not support file cloning
* - An unspecified error occurred * - An unspecified error occurred
*/ */
static bool CloneFileContent(const std::string& source, bool SystemTools::CloneFileContent(const std::string& source,
const std::string& destination) const std::string& destination)
{ {
#if defined(__linux) && defined(FICLONE) #if defined(__linux) && defined(FICLONE)
int in = open(source.c_str(), O_RDONLY); int in = open(source.c_str(), O_RDONLY);
...@@ -2410,9 +2407,9 @@ bool SystemTools::CopyFileAlways(const std::string& source, ...@@ -2410,9 +2407,9 @@ bool SystemTools::CopyFileAlways(const std::string& source,
SystemTools::MakeDirectory(destination_dir); SystemTools::MakeDirectory(destination_dir);
if (!CloneFileContent(source, real_destination)) { if (!SystemTools::CloneFileContent(source, real_destination)) {
// if cloning did not succeed, fall back to blockwise copy // if cloning did not succeed, fall back to blockwise copy
if (!CopyFileContentBlockwise(source, real_destination)) { if (!SystemTools::CopyFileContentBlockwise(source, real_destination)) {
return false; return false;
} }
} }
......
...@@ -577,6 +577,17 @@ public: ...@@ -577,6 +577,17 @@ public:
static bool TextFilesDiffer(const std::string& path1, static bool TextFilesDiffer(const std::string& path1,
const std::string& path2); const std::string& path2);
/**
* Blockwise copy source to destination file
*/
static bool CopyFileContentBlockwise(const std::string& source,
const std::string& destination);
/**
* Clone the source file to the destination file
*/
static bool CloneFileContent(const std::string& source,
const std::string& destination);
/** /**
* Return true if the two files are the same file * Return true if the two files are the same file
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment