Commit f73d1b4f authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

SystemTools: factor out "dest is directory" case from CopyFileIfDifferent()

parent 1ed70242
...@@ -2169,24 +2169,24 @@ std::string SystemTools::ConvertToWindowsOutputPath(const std::string& path) ...@@ -2169,24 +2169,24 @@ std::string SystemTools::ConvertToWindowsOutputPath(const std::string& path)
return ret; return ret;
} }
/**
* Append the filename from the path source to the directory name dir.
*/
static std::string FileInDir(const std::string& source, const std::string& dir)
{
std::string new_destination = dir;
SystemTools::ConvertToUnixSlashes(new_destination);
return new_destination + '/' + SystemTools::GetFilenameName(source);
}
bool SystemTools::CopyFileIfDifferent(const std::string& source, bool SystemTools::CopyFileIfDifferent(const std::string& source,
const std::string& destination) const std::string& destination)
{ {
// special check for a destination that is a directory // special check for a destination that is a directory
// FilesDiffer does not handle file to directory compare // FilesDiffer does not handle file to directory compare
if (SystemTools::FileIsDirectory(destination)) { if (SystemTools::FileIsDirectory(destination)) {
std::string new_destination = destination; const std::string new_destination = FileInDir(source, destination);
SystemTools::ConvertToUnixSlashes(new_destination); return SystemTools::CopyFileIfDifferent(source, new_destination);
new_destination += '/';
std::string source_name = source;
new_destination += SystemTools::GetFilenameName(source_name);
if (SystemTools::FilesDiffer(source, new_destination)) {
return SystemTools::CopyFileAlways(source, destination);
} else {
// the files are the same so the copy is done return
// true
return true;
}
} }
// source and destination are files so do a copy if they // source and destination are files so do a copy if they
// are different // are different
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment