]> gitweb.hamatoma.de Git - crepublib/commitdiff
windows adaptions
authorHamatoma <git.tortouse@hm.f-r-e-i.de>
Wed, 5 Aug 2015 08:56:38 +0000 (10:56 +0200)
committerHamatoma <git.tortouse@hm.f-r-e-i.de>
Wed, 5 Aug 2015 08:56:38 +0000 (10:56 +0200)
base/ReDirectory.cpp
base/ReDirectory.hpp
base/ReSerializable.cpp
base/rebase.hpp
cunit/cuReDirTools.cpp
cunit/cuReFileUtils.cpp
net/ReTCP.cpp
os/ReDirTools.cpp
os/ReDirTools.hpp
os/ReTraverser.cpp

index 67912dfef78e83b576aaae81bb0d30e10b040663..1a99650263ce183164b44728d43d9070a1564664 100644 (file)
@@ -106,9 +106,15 @@ const char* ReDirectory::currentNode() {
  * @param the status info given by <code>lstat()</code>
  */
 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);\r
+       bool rc = handle != INVALID_HANDLE_VALUE;\r
+       if (rc){\r
+               if (GetFileTime(handle, created, accessed, modified) == 0)\r
+                       rc = false;\r
+               CloseHandle(handle);\r
+       }
 #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) {
index 6a19272bcceb8e198d4c1cd33dbe05197947436f..d8f80109fb3f7816c5d204a7f8e6fdadaf97d568 100644 (file)
@@ -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.
index 59404c13ef60cdd31c803df6cd72c6900126d105..f749a75f8c83ece975c949dadb89fc98359fe842 100644 (file)
@@ -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
 }
 /**
index 48f6ea3edad1dfc7bd6163e9196f0dc565af7a58..8b5ff5998b8541eceeb3d7c70c5f241695131666 100644 (file)
@@ -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)
index ddfadd608e01066abd061bff62ab62f22cecbba9..6934c9f839995d79a96a40567c24a81e484b9f3a 100644 (file)
@@ -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 =
index 68f5092074485bb77eeb5e9c26eecbd9fee91385..5b43af60e1638b567535afdf565f5e5486e07e71 100644 (file)
@@ -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";
index 1b1059c0a0297647cf1d7dd6d30119d471a1244e..7363b7229378f8186f9f86de121f5576ba8f0d73 100644 (file)
@@ -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();
index 6757543f1eac9f978e485cf3f03209051c459ff8..45f124a42dbdb97da2d199b8948a2227357c962e 100644 (file)
@@ -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(
index f50b21891f0882081bf6d745566875d5996651b8..6a6321d093fd04d9be6857796907734d99ba1a47 100644 (file)
@@ -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);
index 971d5659b87db333e2c4246734996f18de0f6dfa..815aed3e0821b7aa4c2a9dd4b38fae4b201e388f 100644 (file)
@@ -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);