ENH: Added always/if-different option to CopyADirectory. Added CopyAFile with the same interface.

This commit is contained in:
Brad King 2006-05-05 10:29:27 -04:00
parent 6b9f681f91
commit 523d9ebeed
2 changed files with 34 additions and 6 deletions

View File

@ -1637,11 +1637,26 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination)
return true; return true;
} }
//----------------------------------------------------------------------------
bool SystemTools::CopyAFile(const char* source, const char* destination,
bool always)
{
if(always)
{
return SystemTools::CopyFileAlways(source, destination);
}
else
{
return SystemTools::CopyFileIfDifferent(source, destination);
}
}
/** /**
* Copy a directory content from "source" directory to the directory named by * Copy a directory content from "source" directory to the directory named by
* "destination". * "destination".
*/ */
bool SystemTools::CopyADirectory(const char* source, const char* destination) bool SystemTools::CopyADirectory(const char* source, const char* destination,
bool always)
{ {
Directory dir; Directory dir;
dir.Load(source); dir.Load(source);
@ -1663,14 +1678,16 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination)
kwsys_stl::string fullDestPath = destination; kwsys_stl::string fullDestPath = destination;
fullDestPath += "/"; fullDestPath += "/";
fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum)); fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum));
if (!SystemTools::CopyADirectory(fullPath.c_str(), fullDestPath.c_str())) if (!SystemTools::CopyADirectory(fullPath.c_str(),
fullDestPath.c_str(),
always))
{ {
return false; return false;
} }
} }
else else
{ {
if(!SystemTools::CopyFileAlways(fullPath.c_str(), destination)) if(!SystemTools::CopyAFile(fullPath.c_str(), destination, always))
{ {
return false; return false;
} }

View File

@ -469,10 +469,21 @@ public:
static bool CopyFileAlways(const char* source, const char* destination); static bool CopyFileAlways(const char* source, const char* destination);
/** /**
* Copy content directory to another directory with all files and * Copy a file. If the "always" argument is true the file is always
* subdirectories * copied. If it is false, the file is copied only if it is new or
* has changed.
*/ */
static bool CopyADirectory(const char* source, const char* destination); static bool CopyAFile(const char* source, const char* destination,
bool always = true);
/**
* Copy content directory to another directory with all files and
* subdirectories. If the "always" argument is true all files are
* always copied. If it is false, only files that have changed or
* are new are copied.
*/
static bool CopyADirectory(const char* source, const char* destination,
bool always = true);
/** /**
* Remove a file * Remove a file