summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorSebastien Barre <sebastien.barre@kitware.com>2002-03-25 20:59:47 (GMT)
committerSebastien Barre <sebastien.barre@kitware.com>2002-03-25 20:59:47 (GMT)
commit32fb77fff2a4a95e4f3d505e4e879c06713350d3 (patch)
treefcab0d021e5aaf0ef53727292116ea1f63a3ca8b /Source/cmSystemTools.cxx
parent41be7a401b78f1a46ecebd2c3dbefa38569406b8 (diff)
downloadCMake-32fb77fff2a4a95e4f3d505e4e879c06713350d3.zip
CMake-32fb77fff2a4a95e4f3d505e4e879c06713350d3.tar.gz
CMake-32fb77fff2a4a95e4f3d505e4e879c06713350d3.tar.bz2
ENH: cmCopyFile ; the path to the destination file will be created ; second arg can be a directory.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx29
1 files changed, 27 insertions, 2 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 4d6b23c..5102fa2 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -872,6 +872,7 @@ void cmSystemTools::cmCopyFile(const char* source,
{
const int bufferSize = 4096;
char buffer[bufferSize];
+
std::ifstream fin(source,
#ifdef _WIN32
std::ios::binary |
@@ -883,7 +884,31 @@ void cmSystemTools::cmCopyFile(const char* source,
source, "\"");
return;
}
- std::ofstream fout(destination,
+
+ // If destination is a directory, try to create a file with the same
+ // name as the source in that directory.
+
+ const char* dest = destination;
+
+ std::string new_destination;
+ if(cmSystemTools::FileExists(destination) &&
+ cmSystemTools::FileIsDirectory(destination))
+ {
+ new_destination = destination;
+ cmSystemTools::ConvertToUnixSlashes(new_destination);
+ new_destination += '/';
+ std::string source_name = source;
+ new_destination += cmSystemTools::GetFilenameName(source_name);
+ dest = new_destination.c_str();
+ }
+
+ // Create destination directory
+
+ std::string destination_dir = dest;
+ destination_dir = cmSystemTools::GetFilenamePath(destination_dir);
+ cmSystemTools::MakeDirectory(destination_dir.c_str());
+
+ std::ofstream fout(dest,
#ifdef _WIN32
std::ios::binary |
#endif
@@ -891,7 +916,7 @@ void cmSystemTools::cmCopyFile(const char* source,
if(!fout)
{
cmSystemTools::Error("CopyFile failed to open output file \"",
- destination, "\"");
+ dest, "\"");
return;
}