From ce59cabc70b407a82354174f085aea234f696eba Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Feb 2020 11:41:36 -0500 Subject: KWSys: SystemTools: CopyFileIfDifferent: Fix endless recursion Backport KWSys commit `ea77593a1` (SystemTools: CopyFileIfDifferent: Fix endless recursion, 2020-02-13) for the CMake 3.17 branch. Fixes: #20347 --- Source/kwsys/SystemTools.cxx | 15 +++++++++------ Source/kwsys/testSystemTools.cxx | 9 +++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'Source') diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 39873e630d..d27081b8c6 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2186,12 +2186,15 @@ bool SystemTools::CopyFileIfDifferent(const std::string& source, // FilesDiffer does not handle file to directory compare if (SystemTools::FileIsDirectory(destination)) { const std::string new_destination = FileInDir(source, destination); - return SystemTools::CopyFileIfDifferent(source, new_destination); - } - // source and destination are files so do a copy if they - // are different - if (SystemTools::FilesDiffer(source, destination)) { - return SystemTools::CopyFileAlways(source, destination); + if (!SystemTools::ComparePath(new_destination, destination)) { + return SystemTools::CopyFileIfDifferent(source, new_destination); + } + } else { + // source and destination are files so do a copy if they + // are different + if (SystemTools::FilesDiffer(source, destination)) { + return SystemTools::CopyFileAlways(source, destination); + } } // at this point the files must be the same so return true return true; diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index 1f3a15b591..3f6eeb8c1d 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -1074,6 +1074,15 @@ static bool CheckCopyFileIfDifferent() } } + if (!kwsys::SystemTools::MakeDirectory("dir_a") || + !kwsys::SystemTools::MakeDirectory("dir_b")) { + return false; + } + + if (!kwsys::SystemTools::CopyFileIfDifferent("dir_a/", "dir_b")) { + ret = false; + } + return ret; } -- cgit v1.2.1