diff options
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 167 |
1 files changed, 15 insertions, 152 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 545e6c5..6359d60 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -6,7 +6,6 @@ #include "cmDuration.h" #include "cmProcessOutput.h" #include "cmRange.h" -#include "cm_sys_stat.h" #include "cm_uv.h" #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -60,7 +59,6 @@ #else # include <sys/time.h> # include <unistd.h> -# include <utime.h> #endif #if defined(_WIN32) && \ @@ -90,18 +88,6 @@ static bool cm_isspace(char c) return ((c & 0x80) == 0) && isspace(c); } -class cmSystemToolsFileTime -{ -public: -#if defined(_WIN32) && !defined(__CYGWIN__) - FILETIME timeCreation; - FILETIME timeLastAccess; - FILETIME timeLastWrite; -#else - struct utimbuf timeBuf; -#endif -}; - #if !defined(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE) // For GetEnvironmentVariables # if defined(_WIN32) @@ -134,29 +120,6 @@ static int cm_archive_read_open_file(struct archive* a, const char* file, #endif #ifdef _WIN32 -class cmSystemToolsWindowsHandle -{ -public: - cmSystemToolsWindowsHandle(HANDLE h) - : handle_(h) - { - } - ~cmSystemToolsWindowsHandle() - { - if (this->handle_ != INVALID_HANDLE_VALUE) { - CloseHandle(this->handle_); - } - } - explicit operator bool() const - { - return this->handle_ != INVALID_HANDLE_VALUE; - } - bool operator!() const { return this->handle_ == INVALID_HANDLE_VALUE; } - operator HANDLE() const { return this->handle_; } - -private: - HANDLE handle_; -}; #elif defined(__APPLE__) # include <crt_externs.h> @@ -249,26 +212,6 @@ std::string cmSystemTools::TrimWhitespace(const std::string& s) return std::string(start, stop + 1); } -void cmSystemTools::Error(const char* m1, const char* m2, const char* m3, - const char* m4) -{ - std::string message = "CMake Error: "; - if (m1) { - message += m1; - } - if (m2) { - message += m2; - } - if (m3) { - message += m3; - } - if (m4) { - message += m4; - } - cmSystemTools::s_ErrorOccured = true; - cmSystemTools::Message(message, "Error"); -} - void cmSystemTools::Error(const std::string& m) { std::string message = "CMake Error: " + m; @@ -1746,6 +1689,16 @@ void list_item_verbose(FILE* out, struct archive_entry* entry) fflush(out); } +void ArchiveError(const char* m1, struct archive* a) +{ + std::string message(m1); + const char* m2 = archive_error_string(a); + if (m2) { + message += m2; + } + cmSystemTools::Error(message); +} + bool la_diagnostic(struct archive* ar, __LA_SSIZE_T r) { // See archive.h definition of ARCHIVE_OK for return values. @@ -1815,8 +1768,7 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) struct archive_entry* entry; int r = cm_archive_read_open_file(a, outFileName, 10240); if (r) { - cmSystemTools::Error("Problem with archive_read_open_file(): ", - archive_error_string(a)); + ArchiveError("Problem with archive_read_open_file(): ", a); archive_write_free(ext); archive_read_close(a); return false; @@ -1827,8 +1779,7 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) break; } if (r != ARCHIVE_OK) { - cmSystemTools::Error("Problem with archive_read_next_header(): ", - archive_error_string(a)); + ArchiveError("Problem with archive_read_next_header(): ", a); break; } if (verbose) { @@ -1846,8 +1797,7 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) if (extract) { r = archive_write_disk_set_options(ext, ARCHIVE_EXTRACT_TIME); if (r != ARCHIVE_OK) { - cmSystemTools::Error("Problem with archive_write_disk_set_options(): ", - archive_error_string(ext)); + ArchiveError("Problem with archive_write_disk_set_options(): ", ext); break; } @@ -1858,8 +1808,7 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) } r = archive_write_finish_entry(ext); if (r != ARCHIVE_OK) { - cmSystemTools::Error("Problem with archive_write_finish_entry(): ", - archive_error_string(ext)); + ArchiveError("Problem with archive_write_finish_entry(): ", ext); break; } } @@ -1871,8 +1820,7 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) } # endif else { - cmSystemTools::Error("Problem with archive_write_header(): ", - archive_error_string(ext)); + ArchiveError("Problem with archive_write_header(): ", ext); cmSystemTools::Error("Current file: " + cm_archive_entry_pathname(entry)); break; @@ -2098,91 +2046,6 @@ void cmSystemTools::DoNotInheritStdPipes() #endif } -bool cmSystemTools::CopyFileTime(const std::string& fromFile, - const std::string& toFile) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - cmSystemToolsWindowsHandle hFrom = CreateFileW( - SystemTools::ConvertToWindowsExtendedPath(fromFile).c_str(), GENERIC_READ, - FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); - cmSystemToolsWindowsHandle hTo = CreateFileW( - SystemTools::ConvertToWindowsExtendedPath(toFile).c_str(), - FILE_WRITE_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); - if (!hFrom || !hTo) { - return false; - } - FILETIME timeCreation; - FILETIME timeLastAccess; - FILETIME timeLastWrite; - if (!GetFileTime(hFrom, &timeCreation, &timeLastAccess, &timeLastWrite)) { - return false; - } - return SetFileTime(hTo, &timeCreation, &timeLastAccess, &timeLastWrite) != 0; -#else - struct stat fromStat; - if (stat(fromFile.c_str(), &fromStat) < 0) { - return false; - } - - struct utimbuf buf; - buf.actime = fromStat.st_atime; - buf.modtime = fromStat.st_mtime; - return utime(toFile.c_str(), &buf) >= 0; -#endif -} - -cmSystemToolsFileTime* cmSystemTools::FileTimeNew() -{ - return new cmSystemToolsFileTime; -} - -void cmSystemTools::FileTimeDelete(cmSystemToolsFileTime* t) -{ - delete t; -} - -bool cmSystemTools::FileTimeGet(const std::string& fname, - cmSystemToolsFileTime* t) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - cmSystemToolsWindowsHandle h = CreateFileW( - SystemTools::ConvertToWindowsExtendedPath(fname).c_str(), GENERIC_READ, - FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); - if (!h) { - return false; - } - if (!GetFileTime(h, &t->timeCreation, &t->timeLastAccess, - &t->timeLastWrite)) { - return false; - } -#else - struct stat st; - if (stat(fname.c_str(), &st) < 0) { - return false; - } - t->timeBuf.actime = st.st_atime; - t->timeBuf.modtime = st.st_mtime; -#endif - return true; -} - -bool cmSystemTools::FileTimeSet(const std::string& fname, - const cmSystemToolsFileTime* t) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - cmSystemToolsWindowsHandle h = CreateFileW( - SystemTools::ConvertToWindowsExtendedPath(fname).c_str(), - FILE_WRITE_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); - if (!h) { - return false; - } - return SetFileTime(h, &t->timeCreation, &t->timeLastAccess, - &t->timeLastWrite) != 0; -#else - return utime(fname.c_str(), &t->timeBuf) >= 0; -#endif -} - #ifdef _WIN32 # ifndef CRYPT_SILENT # define CRYPT_SILENT 0x40 /* Not defined by VS 6 version of header. */ |