ENH: cmCopyFile ; the path to the destination file will be created ; second arg can be a directory.
This commit is contained in:
parent
41be7a401b
commit
32fb77fff2
|
@ -25,9 +25,9 @@ void CMakeCommandUsage(const char* program)
|
||||||
errorStream << "cmake version " << cmMakefile::GetMajorVersion()
|
errorStream << "cmake version " << cmMakefile::GetMajorVersion()
|
||||||
<< "." << cmMakefile::GetMinorVersion() << "\n";
|
<< "." << cmMakefile::GetMinorVersion() << "\n";
|
||||||
errorStream << "Usage: " << program << " [command] [arguments ...]\n"
|
errorStream << "Usage: " << program << " [command] [arguments ...]\n"
|
||||||
<< " Available commands: \n"
|
<< "Available commands: \n"
|
||||||
<< " copy file1 file2 - copy first file to the second one\n"
|
<< " copy file destination - copy file to destination (either file or directory)\n"
|
||||||
<< " remove file1 file2 ... - remove the file(s)\n";
|
<< " remove file1 file2 ... - remove the file(s)\n";
|
||||||
errorStream << std::ends;
|
errorStream << std::ends;
|
||||||
cmSystemTools::Error(errorStream.str());
|
cmSystemTools::Error(errorStream.str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -872,6 +872,7 @@ void cmSystemTools::cmCopyFile(const char* source,
|
||||||
{
|
{
|
||||||
const int bufferSize = 4096;
|
const int bufferSize = 4096;
|
||||||
char buffer[bufferSize];
|
char buffer[bufferSize];
|
||||||
|
|
||||||
std::ifstream fin(source,
|
std::ifstream fin(source,
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::ios::binary |
|
std::ios::binary |
|
||||||
|
@ -883,7 +884,31 @@ void cmSystemTools::cmCopyFile(const char* source,
|
||||||
source, "\"");
|
source, "\"");
|
||||||
return;
|
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
|
#ifdef _WIN32
|
||||||
std::ios::binary |
|
std::ios::binary |
|
||||||
#endif
|
#endif
|
||||||
|
@ -891,7 +916,7 @@ void cmSystemTools::cmCopyFile(const char* source,
|
||||||
if(!fout)
|
if(!fout)
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("CopyFile failed to open output file \"",
|
cmSystemTools::Error("CopyFile failed to open output file \"",
|
||||||
destination, "\"");
|
dest, "\"");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue