* Tests whether the buffer ends with a given a byte sequence.
*
* @param tail the byte sequence to test
- * @param tailLength -1: <code>strlen(tail)</code><br>
+ * @param tailLength -1: <code>strlen(tail)</code><br>
* otherwise: the length of <code>tail</code>
* @param ignoreCase <code>true</code>: the comparison is case insensitive<br>
* <code>false</code>: the comparison is case sensitive<br>
#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);
* @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);
}
# 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__
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
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:
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());
ReRandomizer::~ReRandomizer() {
}
+#if defined __linux__
inline int abs(int x) { return x < 0 ? -x : x; }
-
+#endif
/**
* @brief Returns the next random character.
*
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){
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
*/
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){
.arg(fullName).arg(errno).end();
rc = false;
}
+#endif
return rc;
}
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){
// 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)"))
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
}
}
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();
ReDirStatus_t::Type_t ReDirStatus_t::type(){\r
Type_t rc = TF_UNDEF;\r
#if defined __linux__\r
+ int flags = m_status.st_mode;\r
+ if (flags == 0 || S_ISREG(flags))\r
+ rc = TF_REGULAR;\r
+ else if (S_ISDIR(flags)){\r
+ rc = TF_SUBDIR;\r
+ } else if (S_ISLNK(flags))\r
+ rc = TF_LINK;\r
+ else if (S_ISCHR(flags))\r
+ rc = TF_CHAR;\r
+ else if (S_ISBLK(flags))\r
+ rc = TF_BLOCK;\r
+ else if (S_ISFIFO(flags))\r
+ rc = TF_PIPE;\r
+ else if (S_ISSOCK(flags))\r
+ rc = TF_SOCKET;\r
+ else\r
+ rc = TF_OTHER;\r
#elif defined __WIN32__\r
int flags = (m_data.dwFileAttributes & ~(FILE_ATTRIBUTE_READONLY\r
| FILE_ATTRIBUTE_HIDDEN \r
break;\r
if (m_maxAge != 0 && ReDirStatus_t::filetimeToTime(entry.modified()) < m_maxAge)\r
break;\r
- if (m_nodePatterns != NULL && ! m_nodePatterns->match(entry.node()))\r
+ const char* node = entry.node();\r
+ if (m_nodePatterns != NULL && ! m_nodePatterns->match(node))\r
break;\r
rc = true;\r
} while(false);\r