diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2017-03-01 18:41:50 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-03-06 15:38:58 (GMT) |
commit | aba92ffd92bb1cc4bbe898b7abe65347b0468d33 (patch) | |
tree | 7fff657ef3fe0dd115886283b808025cfa8faa34 /Source/CPack | |
parent | 047a5e4d6656f362151b855b34c259708b8419ba (diff) | |
download | CMake-aba92ffd92bb1cc4bbe898b7abe65347b0468d33.zip CMake-aba92ffd92bb1cc4bbe898b7abe65347b0468d33.tar.gz CMake-aba92ffd92bb1cc4bbe898b7abe65347b0468d33.tar.bz2 |
cmWorkingDirectory: use the new class
These functions just need to change the directory for a block of code
and then go back to the caller's expected location. Use
cmWorkingDirectory to ensure that all return paths are handled.
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/cmCPackArchiveGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/CPack/cmCPackGenerator.cxx | 4 |
2 files changed, 5 insertions, 9 deletions
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 9d9cd66..cc01b0c 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -7,6 +7,7 @@ #include "cmCPackLog.h" #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" +#include "cmWorkingDirectory.h" #include <map> #include <ostream> @@ -37,9 +38,8 @@ int cmCPackArchiveGenerator::addOneComponentToArchive( // Add the files of this component to the archive std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); localToplevel += "/" + component->Name; - std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); // Change to local toplevel - cmSystemTools::ChangeDirectory(localToplevel); + cmWorkingDirectory workdir(localToplevel); std::string filePrefix; if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) { filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME"); @@ -64,8 +64,6 @@ int cmCPackArchiveGenerator::addOneComponentToArchive( return 0; } } - // Go back to previous dir - cmSystemTools::ChangeDirectory(dir); return 1; } @@ -227,8 +225,7 @@ int cmCPackArchiveGenerator::PackageFiles() // CASE 3 : NON COMPONENT package. DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); std::vector<std::string>::const_iterator fileIt; - std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(toplevel); + cmWorkingDirectory workdir(toplevel); for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) { // Get the relative path to the file std::string rp = @@ -241,7 +238,6 @@ int cmCPackArchiveGenerator::PackageFiles() return 0; } } - cmSystemTools::ChangeDirectory(dir); // The destructor of cmArchiveWrite will close and finish the write return 1; } diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index e1a4a2a..f6ea8cf 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -16,6 +16,7 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmStateSnapshot.h" +#include "cmWorkingDirectory.h" #include "cmXMLSafe.h" #include "cm_auto_ptr.hxx" #include "cmake.h" @@ -383,7 +384,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( goToDir += "/" + subdir; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Change dir to: " << goToDir << std::endl); - cmSystemTools::ChangeDirectory(goToDir); + cmWorkingDirectory workdir(goToDir); for (symlinkedIt = symlinkedFiles.begin(); symlinkedIt != symlinkedFiles.end(); ++symlinkedIt) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: " @@ -408,7 +409,6 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: " << curDir << std::endl); - cmSystemTools::ChangeDirectory(curDir); } } } |