summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorKan-Ru Chen <kanru@0xlab.org>2010-07-05 17:04:37 +0800
committerKan-Ru Chen <kanru@0xlab.org>2010-07-09 11:03:14 +0800
commit24d22be31cbb1325553db5cf58c714067c8f65cc (patch)
tree8b3bf7176b3250979250eaa5627476cc82590aaf /libs
parentf5f11eb01c7f2ea82e5cd91824bf4e053d4dfd69 (diff)
downloadbuild-24d22be31cbb1325553db5cf58c714067c8f65cc.zip
build-24d22be31cbb1325553db5cf58c714067c8f65cc.tar.gz
build-24d22be31cbb1325553db5cf58c714067c8f65cc.tar.bz2
acp: Ensure dst mtime always greater or equal to src mtime
When copying files from file systems that support high resolution mtime, we should not truncating the nsec part. Instead we should increase the dst mtime by one sec to prevent dst mtime to become less than src mtime. Change-Id: I2b4200c72c4e6ee8aae875b5e64701324799afc7
Diffstat (limited to 'libs')
-rw-r--r--libs/host/CopyFile.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/libs/host/CopyFile.c b/libs/host/CopyFile.c
index a822b41..98adcff 100644
--- a/libs/host/CopyFile.c
+++ b/libs/host/CopyFile.c
@@ -63,6 +63,22 @@ static bool isSourceNewer(const struct stat* pSrcStat, const struct stat* pDstSt
}
/*
+ * Returns true if the source file has high resolution modification
+ * date. Cygwin doesn't support st_mtim in normal build, so always
+ * return false.
+ */
+static bool isHiresMtime(const struct stat* pSrcStat)
+{
+#ifdef WIN32_EXE
+ return 0;
+#elif defined(MACOSX_RSRC)
+ return pSrcStat->st_mtimespec.tv_nsec > 0;
+#else
+ return pSrcStat->st_mtim.tv_nsec > 0;
+#endif
+}
+
+/*
* Returns true if the source and destination files are actually the
* same thing. We detect this by checking the inode numbers, which seems
* to work on Cygwin.
@@ -151,6 +167,8 @@ static int setPermissions(const char* dst, const struct stat* pSrcStat, unsigned
*/
ut.actime = pSrcStat->st_atime;
ut.modtime = pSrcStat->st_mtime;
+ if (isHiresMtime(pSrcStat))
+ ut.modtime += 1;
if (utime(dst, &ut) != 0) {
DBUG(("--- unable to set timestamps on '%s': %s\n",
dst, strerror(errno)));