diff --git a/SystemTools.cxx b/SystemTools.cxx
index bf6f458e11f4f703d6b4f5d26dc5bf7ca5218207..8a481d654855abf01ad4097c918f21a2eb91c217 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -2375,6 +2375,10 @@ bool SystemTools::CopyFileAlways(const kwsys_stl::string& source, const kwsys_st
       {
       fout.write(buffer, fin.gcount());
       }
+    else
+      {
+      break;
+      }
     }
 
   // Make sure the operating system has finished writing the file