summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2007-10-05 13:46:28 (GMT)
committerBrad King <brad.king@kitware.com>2007-10-05 13:46:28 (GMT)
commita2b2742543ee952504c03807aa787c051a4abe72 (patch)
tree78741704d92355714781396616fb523d1441439f /Source/cmSystemTools.cxx
parentb5ca9ba3c8cb83127ba25ce88e9e8a7f1987d9e1 (diff)
downloadCMake-a2b2742543ee952504c03807aa787c051a4abe72.zip
CMake-a2b2742543ee952504c03807aa787c051a4abe72.tar.gz
CMake-a2b2742543ee952504c03807aa787c051a4abe72.tar.bz2
ENH: During file installation treat the source file as a dependency of the installed file. Install the file only if the destination is older than the source. Set the file times on the installed file to match those of the source file. This should greatly improve the speed of repeated installations because it removes the comparison of file contents. This addresses bug#3349.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx64
1 files changed, 64 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 04d6885..1c2ecc9 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -32,6 +32,7 @@
#endif
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__))
+# define CM_SYSTEM_TOOLS_WINDOWS
#include <string.h>
#include <windows.h>
#include <direct.h>
@@ -41,6 +42,7 @@
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
+#include <utime.h>
#endif
#include <sys/stat.h>
@@ -66,6 +68,26 @@ extern char** environ;
# endif
#endif
+#ifdef CM_SYSTEM_TOOLS_WINDOWS
+class cmSystemToolsWindowsHandle
+{
+public:
+ cmSystemToolsWindowsHandle(HANDLE h): handle_(h) {}
+ ~cmSystemToolsWindowsHandle()
+ {
+ if(this->handle_ != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(this->handle_);
+ }
+ }
+ operator bool() const { return this->handle_ != INVALID_HANDLE_VALUE; }
+ operator !() const { return this->handle_ == INVALID_HANDLE_VALUE; }
+ operator HANDLE() const { return this->handle_; }
+private:
+ HANDLE handle_;
+};
+#endif
+
bool cmSystemTools::s_RunCommandHideConsole = false;
bool cmSystemTools::s_DisableRunCommandOutput = false;
bool cmSystemTools::s_ErrorOccured = false;
@@ -2006,3 +2028,45 @@ void cmSystemTools::DoNotInheritStdPipes()
}
#endif
}
+
+//----------------------------------------------------------------------------
+bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ cmSystemToolsWindowsHandle hFrom =
+ CreateFile(fromFile, GENERIC_READ, FILE_SHARE_READ, 0,
+ OPEN_EXISTING, 0, 0);
+ cmSystemToolsWindowsHandle hTo =
+ CreateFile(toFile, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+ if(!hFrom || !hTo)
+ {
+ return false;
+ }
+ FILETIME timeCreation;
+ FILETIME timeLastAccess;
+ FILETIME timeLastWrite;
+ if(!GetFileTime(hFrom, &timeCreation, &timeLastAccess, &timeLastWrite))
+ {
+ return false;
+ }
+ if(!SetFileTime(hFrom, &timeCreation, &timeLastAccess, &timeLastWrite))
+ {
+ return false;
+ }
+#else
+ struct stat fromStat;
+ if(stat(fromFile, &fromStat) < 0)
+ {
+ return false;
+ }
+
+ struct utimbuf buf;
+ buf.actime = fromStat.st_atime;
+ buf.modtime = fromStat.st_mtime;
+ if(utime(toFile, &buf) < 0)
+ {
+ return false;
+ }
+#endif
+ return true;
+}