From 5f52f9946c0b6f5889ae99d11317ff91855395fb Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Wed, 5 Aug 2015 10:56:38 +0200 Subject: [PATCH] windows adaptions --- base/ReDirectory.cpp | 27 ++++++++++++++++++++++++--- base/ReDirectory.hpp | 16 ++++++++-------- base/ReSerializable.cpp | 7 ++----- base/rebase.hpp | 1 + cunit/cuReDirTools.cpp | 8 ++++---- cunit/cuReFileUtils.cpp | 7 ++++++- net/ReTCP.cpp | 1 + os/ReDirTools.cpp | 4 ++-- os/ReDirTools.hpp | 1 + os/ReTraverser.cpp | 3 +-- 10 files changed, 50 insertions(+), 25 deletions(-) diff --git a/base/ReDirectory.cpp b/base/ReDirectory.cpp index 67912df..1a99650 100644 --- a/base/ReDirectory.cpp +++ b/base/ReDirectory.cpp @@ -106,9 +106,15 @@ const char* ReDirectory::currentNode() { * @param the status info given by lstat() */ struct stat& ReDirectory::currentLStat(){ +#if defined linux if (m_stat.st_gid == (mode_t)-1 && filetimeIsUndefined(m_stat.st_mtim)){ lstat(currentFull().str(), &m_stat); } +#elif defined __WIN32__ + if (m_stat.st_mtime == (time_t) -1){ + stat(currentFull().str(), &m_stat); + } +#endif return m_stat; } @@ -121,7 +127,7 @@ bool ReDirectory::currentIsDir(){ #if defined __linux__ return S_ISDIR(currentLStat().st_mode); #elif defined __WIN32__ - return + return (m_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; #endif } @@ -134,7 +140,7 @@ ReFileTime_t ReDirectory::currentModified(){ #if defined __linux__ return currentLStat().st_mtim; #elif defined __WIN32__ - return + return m_data.ftLastWriteTime; #endif } @@ -184,9 +190,20 @@ bool ReDirectory::filetime(const char* filename, ReFileTime_t* modified, bool rc = stat(filename, &info) == 0; if (rc){ if (modified != NULL) - ; + *m_modified = info.st_mtim; + if (created != NULL) + *created = info.st_ctim; + if (accessed != NULL + *accessed = info.st_atim; } #elif defined __WIN32__ + HANDLE handle = CreateFile(filename, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); + bool rc = handle != INVALID_HANDLE_VALUE; + if (rc){ + if (GetFileTime(handle, created, accessed, modified) == 0) + rc = false; + CloseHandle(handle); + } #endif return rc; } @@ -248,7 +265,11 @@ bool ReDirectory::findNext() { bool rc = false; m_currentFull.clear(); m_stat.st_gid = -1; +#ifdef linux setFiletimeUndef(m_stat.st_mtim); +#elif defined __WIN32__ + m_stat.st_mtime = (time_t) -1; +#endif if (m_valid) { #if defined __linux__ while (!rc && (m_entry = readdir(m_dir)) != NULL) { diff --git a/base/ReDirectory.hpp b/base/ReDirectory.hpp index 6a19272..d8f8010 100644 --- a/base/ReDirectory.hpp +++ b/base/ReDirectory.hpp @@ -98,8 +98,8 @@ inline bool operator ==(const ReFileTime_t& op1, const ReFileTime_t& op2){ #if defined __linux__ return op1.tv_sec == op2.tv_sec && op1.tv_nsec == op2.tv_nsec; #else - return time1.dwHighDateTime == time2.dwHighDateTime - && time1.dwLowDateTime == time2.dwLowDateTime; + return op1.dwHighDateTime == op2.dwHighDateTime + && op1.dwLowDateTime == op2.dwLowDateTime; #endif } /** Returns whether a filetime is equal than another. @@ -119,9 +119,9 @@ inline bool operator >(const ReFileTime_t& op1, const ReFileTime_t& op2){ #if defined __linux__ return op1.tv_sec > op2.tv_sec || op1.tv_sec == op2.tv_sec && op1.tv_nsec > op2.tv_nsec; #else - return time1.dwHighDateTime > time2.dwHighDateTime - || (time1.dwHighDateTime == time2.dwHighDateTime - && time1.dwLowDateTime > time2.dwLowDateTime); + return op1.dwHighDateTime > op2.dwHighDateTime + || (op1.dwHighDateTime == op2.dwHighDateTime + && op1.dwLowDateTime > op2.dwLowDateTime); #endif } /** Returns whether a filetime is greater (younger) or equal than another. @@ -133,9 +133,9 @@ inline bool operator >=(const ReFileTime_t& op1, const ReFileTime_t& op2){ #if defined __linux__ return op1.tv_sec > op2.tv_sec || op1.tv_sec == op2.tv_sec && op1.tv_nsec >= op2.tv_nsec; #else - return time1.dwHighDateTime > time2.dwHighDateTime - || (time1.dwHighDateTime == time2.dwHighDateTime - && time1.dwLowDateTime >= time2.dwLowDateTime); + return op1.dwHighDateTime > op2.dwHighDateTime + || (op1.dwHighDateTime == op2.dwHighDateTime + && op1.dwLowDateTime >= op2.dwLowDateTime); #endif } /** Returns whether a filetime is lower (younger) than another. diff --git a/base/ReSerializable.cpp b/base/ReSerializable.cpp index 59404c1..f749a75 100644 --- a/base/ReSerializable.cpp +++ b/base/ReSerializable.cpp @@ -83,13 +83,10 @@ ReSerializable::~ReSerializable() { */ void ReSerializable::packFileTime(ReByteArray& sequence, const ReFileTime_t& time) { - uint64_t value; #if defined __linux__ - value = (time.tv_sec << 32) + time.tv_nsec; - sequence.appendBits64(int64_t(value)); + sequence.appendBits64(((int64_t) time.tv_sec << 32) + time.tv_nsec); #elif defined __WIN32__ -//#error "missing impl" - assert(false); + sequence.appendBits64((int64_t(time.dwHighDateTime) << 32) + time.dwLowDateTime); #endif } /** diff --git a/base/rebase.hpp b/base/rebase.hpp index 48f6ea3..8b5ff59 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -46,6 +46,7 @@ typedef u_int64_t uint64_t; typedef u_int8_t uint8_t; typedef __off_t ReFileSize_t; typedef struct timespec ReFileTime_t; +# define _unlink unlink # define _strdup strdup # define _unlink unlink # define _strnicmp(s1, s2, n) strncasecmp(s1, s2, n) diff --git a/cunit/cuReDirTools.cpp b/cunit/cuReDirTools.cpp index ddfadd6..6934c9f 100644 --- a/cunit/cuReDirTools.cpp +++ b/cunit/cuReDirTools.cpp @@ -144,7 +144,7 @@ private: #if defined __linux__ return data.tv_sec; #elif defined __WIN32__ - return (int) ReDirStatus_t::filetimeToTime(&data); + return (int) ReFileUtils::filetimeToTime(&data); #endif } const char* makeDir(const char* relPath) { @@ -467,10 +467,10 @@ private: for(const char** pFile = s_allFiles; *pFile != NULL; pFile++){ ReByteArray fullTarget(target); fullTarget.append(*pFile); - if (fullTarget.endsWith(".txt") || ! fullTarget.contains("cache") >= 0){ - checkT(stat(fullTarget.str(), &info)); + if (fullTarget.endsWith(".txt") || ! fullTarget.contains("cache")){ + checkT(stat(fullTarget.str(), &info) != 0); } else { - checkF(stat(fullTarget.str(), &info)); + checkF(stat(fullTarget.str(), &info) != 0); } } static const char* content = diff --git a/cunit/cuReFileUtils.cpp b/cunit/cuReFileUtils.cpp index 68f5092..5b43af6 100644 --- a/cunit/cuReFileUtils.cpp +++ b/cunit/cuReFileUtils.cpp @@ -39,7 +39,7 @@ private: void testSetFiles(){ ReByteArray name = ReFileUtils::tempFile("setfile_test.dat"); struct stat info; - unlink(name.str()); + _unlink(name.str()); ReFileUtils::writeString(name.str(), ""); checkEqu(0, stat(name.str(), &info)); struct tm time1; @@ -58,8 +58,13 @@ private: ReFileUtils::timeToFiletime(time2 + diff, time4); ReFileUtils::setTimes(name.str(), time3, &time4, NULL); checkEqu(0, stat(name.str(), &info)); +#if defined __linux__ checkT(time2 == info.st_mtim.tv_sec); checkT(time2 + diff == info.st_atim.tv_sec); +#elif defined __WIN32__ + checkT(time2 == info.st_mtime); + checkT(time2 + diff == info.st_atime); +#endif } void testTempFile(){ const char* subdir = "refileutiltest"; diff --git a/net/ReTCP.cpp b/net/ReTCP.cpp index 1b1059c..7363b72 100644 --- a/net/ReTCP.cpp +++ b/net/ReTCP.cpp @@ -437,6 +437,7 @@ void ReTCPServerConnection::run() { } while (rc != ReNetCommandHandler::PS_STOP && !m_shouldStop); m_pool->setShouldStop(); } catch (ReTCPDisconnectException& e) { + reUseParam(e); rc = ReNetCommandHandler::PS_CLOSED; } close(); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 6757543..45f124a 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -2189,7 +2189,7 @@ bool ReDirSync::adaptProperties(const char* source, fprintf(output, "%c%s%s\n", prefix, source, changed.str()); } #else -#error "not implemented" + // nothing to do #endif return rc; } @@ -2444,7 +2444,7 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength, return rc; } -static void printStatus(FILE* fp, double duration, int files, int sumSizes, +static void printStatus(FILE* fp, double duration, int files, int64_t sumSizes, int treeDirs, int treeFiles, int64_t treeSumSizes) { fprintf(fp, i18n( diff --git a/os/ReDirTools.hpp b/os/ReDirTools.hpp index f50b218..6a6321d 100644 --- a/os/ReDirTools.hpp +++ b/os/ReDirTools.hpp @@ -283,6 +283,7 @@ public: ReFileProperties_t* srcProps, const char* target, struct stat* trgProps, VerboseLevel verbose = V_QUIET, char prefix = ':', FILE* output = NULL, ReLogger* logger = NULL); + static bool copyFile(const char* source, bool isLink, ReFileProperties_t* properties, const char* target, ReByteArray& buffer, ReLogger* logger = NULL); diff --git a/os/ReTraverser.cpp b/os/ReTraverser.cpp index 971d565..815aed3 100644 --- a/os/ReTraverser.cpp +++ b/os/ReTraverser.cpp @@ -587,8 +587,7 @@ ReByteArray& ReDirEntryFilter::serialize(ReByteArray& sequence) { sequence.appendBits64(int64_t(value)); value = (m_minAge.tv_sec << 32) + m_minAge.tv_nsec; #elif defined __WIN32__ -// #error "missing impl" - assert(false); + value = (int64_t(m_minAge.dwHighDateTime) << 32) + m_minAge.dwLowDateTime; #endif sequence.appendBits64(int64_t(value)); packBool(sequence, m_allDirectories); -- 2.39.5