summaryrefslogtreecommitdiff
path: root/lib/raidfile/RaidFileUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/raidfile/RaidFileUtil.cpp')
-rw-r--r--lib/raidfile/RaidFileUtil.cpp64
1 files changed, 28 insertions, 36 deletions
diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp
index 7c6299ec..48625997 100644
--- a/lib/raidfile/RaidFileUtil.cpp
+++ b/lib/raidfile/RaidFileUtil.cpp
@@ -14,10 +14,30 @@
#include "RaidFileUtil.h"
#include "FileModificationTime.h"
-#include "RaidFileRead.h" // for type definition
+#include "RaidFileRead.h" // for type definition
#include "MemLeakFindOn.h"
+int64_t adjust_timestamp(int64_t timestamp, size_t file_size)
+{
+#ifndef BOX_RELEASE_BUILD
+ // Remove the microseconds part of the timestamp,
+ // to simulate filesystem with 1-second timestamp
+ // resolution, e.g. MacOS X HFS, old Linuxes.
+ // Otherwise it's easy to write tests that rely
+ // on more accurate timestamps, and pass on
+ // platforms that have them, and fail on others.
+ timestamp -= (timestamp % MICRO_SEC_IN_SEC);
+#endif
+
+ // The resolution of timestamps may be very
+ // low, e.g. 1 second. So add the size to it
+ // to give a bit more chance of it changing.
+ // TODO: Make this better.
+ timestamp += file_size;
+
+ return timestamp;
+}
// --------------------------------------------------------------------------
//
@@ -39,8 +59,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet,
*pExistingFiles = 0;
}
- // For stat call, although the results are not examined
- struct stat st;
+ EMU_STRUCT_STAT st;
// check various files
int startDisc = 0;
@@ -50,29 +69,15 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet,
{
*pStartDisc = startDisc;
}
- if(::stat(writeFile.c_str(), &st) == 0)
+ if(EMU_STAT(writeFile.c_str(), &st) == 0)
{
// write file exists, use that
// Get unique ID
if(pRevisionID != 0)
{
- #ifdef WIN32
- *pRevisionID = st.st_mtime;
- #else
- *pRevisionID = FileModificationTime(st);
- #endif
-
-#ifdef BOX_RELEASE_BUILD
- // The resolution of timestamps may be very
- // low, e.g. 1 second. So add the size to it
- // to give a bit more chance of it changing.
- // TODO: Make this better.
- // Disabled in debug mode, to simulate
- // filesystem with 1-second timestamp
- // resolution, e.g. MacOS X HFS, Linux.
- (*pRevisionID) += st.st_size;
-#endif
+ *pRevisionID = FileModificationTime(st);
+ *pRevisionID = adjust_timestamp(*pRevisionID, st.st_size);
}
// return non-raid file
@@ -91,7 +96,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet,
for(int f = 0; f < setSize; ++f)
{
std::string componentFile(RaidFileUtil::MakeRaidComponentName(rDiscSet, rFilename, (f + startDisc) % setSize));
- if(::stat(componentFile.c_str(), &st) == 0)
+ if(EMU_STAT(componentFile.c_str(), &st) == 0)
{
// Component file exists, add to count
rfCount++;
@@ -103,12 +108,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet,
// Revision ID
if(pRevisionID != 0)
{
- #ifdef WIN32
- int64_t rid = st.st_mtime;
- #else
- int64_t rid = FileModificationTime(st);
- #endif
-
+ int64_t rid = FileModificationTime(st);
if(rid > revisionID) revisionID = rid;
revisionIDplus += st.st_size;
}
@@ -116,16 +116,8 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet,
}
if(pRevisionID != 0)
{
+ revisionID = adjust_timestamp(revisionID, revisionIDplus);
(*pRevisionID) = revisionID;
-#ifdef BOX_RELEASE_BUILD
- // The resolution of timestamps may be very low, e.g.
- // 1 second. So add the size to it to give a bit more
- // chance of it changing.
- // TODO: Make this better.
- // Disabled in debug mode, to simulate filesystem with
- // 1-second timestamp resolution, e.g. MacOS X HFS, Linux.
- (*pRevisionID) += revisionIDplus;
-#endif
}
// Return a status based on how many parts are available