From: hama Date: Mon, 26 Jan 2015 23:55:51 +0000 (+0100) Subject: Windows corrections, ReDirSync X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=4b9e1c1ceb137f879d671f0f5e603f46b8aad06b;p=crepublib Windows corrections, ReDirSync --- diff --git a/base/ReByteBuffer.cpp b/base/ReByteBuffer.cpp index 25bd8e5..c61d1eb 100644 --- a/base/ReByteBuffer.cpp +++ b/base/ReByteBuffer.cpp @@ -260,7 +260,7 @@ int ReByteBuffer::count(const char* toCount, size_t lengthToCount){ * Tests whether the buffer ends with a given a byte sequence. * * @param tail the byte sequence to test - * @param tailLength -1: strlen(tail)
+ * @param tailLength -1: strlen(tail)
* otherwise: the length of tail * @param ignoreCase true: the comparison is case insensitive
* false: the comparison is case sensitive
diff --git a/base/ReTestUnit.cpp b/base/ReTestUnit.cpp index af49e6a..c2f3a68 100644 --- a/base/ReTestUnit.cpp +++ b/base/ReTestUnit.cpp @@ -230,7 +230,7 @@ void ReTestUnit::createTestDir(){ #define ALLPERMS 0 #endif if (lstat(name, &info) != 0) - _mkdir(name); + _mkdir(name, ALLPERMS); else{ char cmd[512 + 128]; _snprintf(cmd, sizeof cmd, "rm -Rf %s*", name); @@ -311,7 +311,7 @@ void ReTestUnit::createFile(const char* filename, const char* content){ * @param content the content of the file. If NULL the file will be empty */ void ReTestUnit::createDir(const char* filename){ - _mkdir(filename); + _mkdir(filename, ALLPERMS); } diff --git a/base/rebase.hpp b/base/rebase.hpp index 6f327bb..a623bce 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -37,7 +37,7 @@ typedef u_int64_t uint64_t; # define _stricmp(s1, s2) strcasecmp(s1, s2) # define _snprintf snprintf # define _memcmp(t,s,n) memcmp(t,s,n) -# define _mkdir(path) mkdir(path, ALLPERMS) +# define _mkdir(path, mode) mkdir(path, mode) # define OS_SEPARATOR_CHAR '/' # define OS_SEPARATOR "/" #elif defined __WIN32__ @@ -51,6 +51,8 @@ typedef u_int64_t uint64_t; typedef unsigned long long uint64_t; typedef unsigned char uint8_t; # define S_ISDIR(mode) (((mode) & _S_IFDIR) != 0) +# define ALLPERMS 0 +# define _mkdir(name, mode) _mkdir(name) #endif #define RE_TESTUNIT diff --git a/cunit/cuReTraverser.cpp b/cunit/cuReTraverser.cpp index 245105b..064cdee 100644 --- a/cunit/cuReTraverser.cpp +++ b/cunit/cuReTraverser.cpp @@ -17,7 +17,7 @@ public: TestReTraverser() : ReTestUnit("ReTraverser", __FILE__){ m_base = testDir(); m_base.append("traverser").append(OS_SEPARATOR, -1); - _mkdir(m_base.str()); + _mkdir(m_base.str(), ALLPERMS); run(); } private: @@ -28,7 +28,7 @@ private: m_buffer = m_base; m_buffer.append(relPath); m_buffer.replaceAll("/", 1, OS_SEPARATOR, -1); - _mkdir(m_buffer.str()); + _mkdir(m_buffer.str(), ALLPERMS); struct stat info; if (stat(m_buffer.str(), &info) != 0){ logF(true, "cannot create dir %1$s", m_buffer.str()); diff --git a/math/ReRandomizer.cpp b/math/ReRandomizer.cpp index 7ff8cad..0c55da9 100644 --- a/math/ReRandomizer.cpp +++ b/math/ReRandomizer.cpp @@ -24,8 +24,9 @@ ReRandomizer::ReRandomizer() ReRandomizer::~ReRandomizer() { } +#if defined __linux__ inline int abs(int x) { return x < 0 ? -x : x; } - +#endif /** * @brief Returns the next random character. * @@ -123,7 +124,7 @@ int64_t ReRandomizer::nextInt64(int64_t maxValue, int64_t minValue){ rc = minValue + seed % (maxValue - minValue + 1); else { // int64 overflow: we need a higher precision: - double rc2 = minValue + fmod((double) seed, maxValue - minValue); + double rc2 = (double) minValue + fmod((double) seed, (double) (maxValue - minValue)); rc = (int) rc2; } if (s_trace){ diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 5c3632f..ce6c5cf 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -1082,8 +1082,8 @@ void ReDirSync::copyFile(ReDirStatus_t* entry, const char* target){ props = &entry->m_status; #else ReFileProperties_t properties; - properties.m_modified = entry->modified(); - properties.m_accessed = entry->accessed(); + properties.m_modified = *entry->modified(); + properties.m_accessed = *entry->accessed(); properties.m_size = entry->fileSize(); props = &properties; #endif @@ -1179,8 +1179,9 @@ bool ReDirSync::copyFile(const char* source, ReFileProperties_t* properties, */ bool ReDirSync::setProperties(const char* fullName, ReFileProperties_t* properties, ReLogger* logger){ - struct utimbuf times; bool rc = true; +#if defined __linux__ + struct utimbuf times; times.actime = properties->st_atime; times.modtime = properties->st_mtime; if (utime(fullName, ×) != 0){ @@ -1204,6 +1205,7 @@ bool ReDirSync::setProperties(const char* fullName, .arg(fullName).arg(errno).end(); rc = false; } +#endif return rc; } @@ -1222,9 +1224,9 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength, ReByteBuffer path(directory); int start = 0; #if defined __WIN32__ - start = path.indexOf(":"); + start = path.indexOf(':'); #endif - int ixSlash = start; + int ixSlash = start < 0 ? 0 : start; struct stat info; // for all parents and the full path itself: while(ixSlash >= 0){ @@ -1240,7 +1242,7 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength, // does the node exist? if (lstat(path.str(), &info) != 0){ // no, then we make it: - if (mkdir(path.str(), 0) != 0){ + if (_mkdir(path.str(), ALLPERMS) != 0){ if (logger != NULL) logger->sayF(LOG_ERROR, LC_MAKE_DIR_1, i18n("could not make directory $1 (errno: $2)")) @@ -1249,14 +1251,7 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength, break; } else { #if defined __linux__ - if (properties != NULL){ - //@ToDo: file time - if (chown(path.str(), properties->st_uid, - properties->st_gid) != 0 && logger != NULL) - logger->sayF(LOG_ERROR, LC_MAKE_DIR_2, - i18n("could not change owner/group of directory $1 (errno: $2)")) - .arg(path.str()).arg(errno).end(); - } + setProperties(path.str(), properties); #endif } } @@ -1316,7 +1311,7 @@ void ReDirSync::synchronize(int argc, const char* argv[]){ if (! source.endsWith(sep, 1)){ // the basename of the source will be appended to the target: int startNode = source.rindexOf(sep, 1, 0, source.length() - 1); - target.append(source.str() + startNode, -1); + target.append(source.str() + startNode + 1, -1); } size_t ixSourceRelative = source.length(); size_t ixTargetRelative = target.length(); diff --git a/os/ReTraverser.cpp b/os/ReTraverser.cpp index 3a62141..6c0923e 100644 --- a/os/ReTraverser.cpp +++ b/os/ReTraverser.cpp @@ -157,6 +157,23 @@ bool ReDirStatus_t::findNext(){ ReDirStatus_t::Type_t ReDirStatus_t::type(){ Type_t rc = TF_UNDEF; #if defined __linux__ + int flags = m_status.st_mode; + if (flags == 0 || S_ISREG(flags)) + rc = TF_REGULAR; + else if (S_ISDIR(flags)){ + rc = TF_SUBDIR; + } else if (S_ISLNK(flags)) + rc = TF_LINK; + else if (S_ISCHR(flags)) + rc = TF_CHAR; + else if (S_ISBLK(flags)) + rc = TF_BLOCK; + else if (S_ISFIFO(flags)) + rc = TF_PIPE; + else if (S_ISSOCK(flags)) + rc = TF_SOCKET; + else + rc = TF_OTHER; #elif defined __WIN32__ int flags = (m_data.dwFileAttributes & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN @@ -354,7 +371,8 @@ bool ReDirEntryFilter_t::match(ReDirStatus_t& entry){ break; if (m_maxAge != 0 && ReDirStatus_t::filetimeToTime(entry.modified()) < m_maxAge) break; - if (m_nodePatterns != NULL && ! m_nodePatterns->match(entry.node())) + const char* node = entry.node(); + if (m_nodePatterns != NULL && ! m_nodePatterns->match(node)) break; rc = true; } while(false);