summaryrefslogtreecommitdiffstats
path: root/Source/CPack/cmCPackTarBZip2Generator.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2009-10-30 17:10:56 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2009-10-30 17:10:56 (GMT)
commitfb51d98562a26b6dcde7d3597938a0b707b6b881 (patch)
treeb42fbfb6b27b7a9e2d5068601f61d80e7033dc79 /Source/CPack/cmCPackTarBZip2Generator.cxx
parent0615218bdf3e240e44e539f9eed6c1cf9fbff2d4 (diff)
downloadCMake-fb51d98562a26b6dcde7d3597938a0b707b6b881.zip
CMake-fb51d98562a26b6dcde7d3597938a0b707b6b881.tar.gz
CMake-fb51d98562a26b6dcde7d3597938a0b707b6b881.tar.bz2
Switch to using libarchive from libtar for cpack and cmake -E tar
This allows for a built in bzip and zip capability, so external tools will not be needed for these packagers. The cmake -E tar xf should be able to handle all compression types now as well.
Diffstat (limited to 'Source/CPack/cmCPackTarBZip2Generator.cxx')
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.cxx156
1 files changed, 3 insertions, 153 deletions
diff --git a/Source/CPack/cmCPackTarBZip2Generator.cxx b/Source/CPack/cmCPackTarBZip2Generator.cxx
index de7f16c..52826dc 100644
--- a/Source/CPack/cmCPackTarBZip2Generator.cxx
+++ b/Source/CPack/cmCPackTarBZip2Generator.cxx
@@ -11,29 +11,11 @@
============================================================================*/
#include "cmCPackTarBZip2Generator.h"
-
-#include "cmake.h"
-#include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
-#include "cmSystemTools.h"
-#include "cmMakefile.h"
-#include "cmGeneratedFileStream.h"
-#include "cmCPackLog.h"
-
-#include <cmsys/SystemTools.hxx>
-
-// Includes needed for implementation of RenameFile. This is not in
-// system tools because it is not implemented robustly enough to move
-// files across directories.
-#ifdef _WIN32
-# include <windows.h>
-# include <sys/stat.h>
-#endif
-
//----------------------------------------------------------------------
-cmCPackTarBZip2Generator::cmCPackTarBZip2Generator()
+cmCPackTarBZip2Generator::cmCPackTarBZip2Generator()
+ :cmCPackArchiveGenerator(cmCPackArchiveGenerator::BZIP2,
+ cmCPackArchiveGenerator::TAR)
{
- this->Compress = false;
}
//----------------------------------------------------------------------
@@ -41,135 +23,3 @@ cmCPackTarBZip2Generator::~cmCPackTarBZip2Generator()
{
}
-//----------------------------------------------------------------------
-int cmCPackTarBZip2Generator::InitializeInternal()
-{
- this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
- std::vector<std::string> path;
- std::string pkgPath = cmSystemTools::FindProgram("bzip2", path, false);
- if ( pkgPath.empty() )
- {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find BZip2" << std::endl);
- return 0;
- }
- this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Compress program: "
- << pkgPath.c_str()
- << std::endl);
-
- return this->Superclass::InitializeInternal();
-}
-
-//----------------------------------------------------------------------
-int cmCPackTarBZip2Generator::BZip2File(const char* packageDirFileName)
-{
- int retVal = 0;
- cmOStringStream dmgCmd1;
- dmgCmd1 << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
- << "\" \"" << packageDirFileName
- << "\"";
- retVal = -1;
- std::string output;
- int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output,
- &retVal, 0, this->GeneratorVerbose, 0);
- if ( !res || retVal )
- {
- std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
- tmpFile += "/CompressBZip2.log";
- cmGeneratedFileStream ofs(tmpFile.c_str());
- ofs << "# Run command: " << dmgCmd1.str().c_str() << std::endl
- << "# Output:" << std::endl
- << output.c_str() << std::endl;
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running BZip2 command: "
- << dmgCmd1.str().c_str() << std::endl
- << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
- return 0;
- }
- return 1;
-}
-
-//----------------------------------------------------------------------
-int cmCPackTarBZip2Generator::CompressFiles(const char* outFileName,
- const char* toplevel, const std::vector<std::string>& files)
-{
- std::string packageDirFileName
- = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
- packageDirFileName += ".tar";
- std::string output;
- if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(),
- toplevel, files) )
- {
- return 0;
- }
-
- if(!this->BZip2File(packageDirFileName.c_str()))
- {
- return 0;
- }
-
- std::string compressOutFile = packageDirFileName + ".bz2";
- if ( !cmSystemTools::SameFile(compressOutFile.c_str(), outFileName ) )
- {
- if ( !this->RenameFile(compressOutFile.c_str(), outFileName) )
- {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem renaming: \""
- << compressOutFile.c_str() << "\" to \""
- << (outFileName ? outFileName : "(NULL)") << std::endl);
- return 0;
- }
- }
-
- return 1;
-}
-
-//----------------------------------------------------------------------------
-int cmCPackTarBZip2Generator::RenameFile(const char* oldname,
- const char* newname)
-{
-#ifdef _WIN32
- /* On Windows the move functions will not replace existing files.
- Check if the destination exists. */
- struct stat newFile;
- if(stat(newname, &newFile) == 0)
- {
- /* The destination exists. We have to replace it carefully. The
- MoveFileEx function does what we need but is not available on
- Win9x. */
- OSVERSIONINFO osv;
- DWORD attrs;
-
- /* Make sure the destination is not read only. */
- attrs = GetFileAttributes(newname);
- if(attrs & FILE_ATTRIBUTE_READONLY)
- {
- SetFileAttributes(newname, attrs & ~FILE_ATTRIBUTE_READONLY);
- }
-
- /* Check the windows version number. */
- osv.dwOSVersionInfoSize = sizeof(osv);
- GetVersionEx(&osv);
- if(osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
- {
- /* This is Win9x. There is no MoveFileEx implementation. We
- cannot quite rename the file atomically. Just delete the
- destination and then move the file. */
- DeleteFile(newname);
- return MoveFile(oldname, newname);
- }
- else
- {
- /* This is not Win9x. Use the MoveFileEx implementation. */
- return MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING);
- }
- }
- else
- {
- /* The destination does not exist. Just move the file. */
- return MoveFile(oldname, newname);
- }
-#else
- /* On UNIX we have an OS-provided call to do this atomically. */
- return rename(oldname, newname) == 0;
-#endif
-}
-