]> gitweb.hamatoma.de Git - reqt/commitdiff
ReFileSystem
authorhama <hama@siduction.net>
Tue, 22 Sep 2015 21:39:22 +0000 (23:39 +0200)
committerhama <hama@siduction.net>
Tue, 22 Sep 2015 21:39:22 +0000 (23:39 +0200)
base/ReFileUtils.cpp
base/ReFileUtils.hpp
base/ReMatcher.cpp
base/ReMatcher.hpp
base/ReQStringUtils.cpp
base/ReQStringUtils.hpp
base/rebase.hpp
os/ReFileSystem.cpp
os/ReFileSystem.hpp

index c5f92862fb85ef4f54c1fb2029260722fa0d3cdd..314d22be111e3c4f90234eb8e1634e5de17c0435 100644 (file)
@@ -15,89 +15,18 @@ enum {
        LOC_DELETE_TREE_1 = LOC_FIRST_OF(LOC_FILE), // 11801
        LOC_DELETE_TREE_2,              // 11802
        LOC_DELETE_TREE_3,              // 11803
+       LOC_SET_TIMES_1,                // 11804
 };
 
+QDateTime ReFileUtils::m_undefinedTime;
+
 /**
  * Constructor.
  */
 ReTreeStatistic::ReTreeStatistic() :
-               m_files(0),
-               m_directories(0),
-               m_fileSizes(0L) {
-}
-
-/**
- * Returns whether a path is an absolute path.
- *
- * @param path the path to test
- * @return             <code>true</code>: the path is absolute<br>
- *                             <code>false</code>: the path is relative
- */
-bool ReFileUtils::isAbsolutPath(const QString& path) {
-       bool rc;
-#ifdef __linux__
-       rc = path.startsWith(OS_SEPARATOR);
-#else
-       rc = path.length() > 3 && path.at(1) == ':' && path.at(2) == OS_SEPARATOR
-                                                          || path.startsWith("\\\\");
-#endif
-       return rc;
-}
-
-/**
- * Returns whether a path is an absolute path.
- *
- * @param path the path to test
- * @return             <code>true</code>: the path is absolute<br>
- *                             <code>false</code>: the path is relative
- */
-bool ReFileUtils::isAbsolutPath(const char* path)
-{
-       bool rc;
-#ifdef __linux__
-       rc = path[0] == OS_SEPARATOR;
-#else
-       rc = isalpha(path[0]) && path[1] == ':' && path[2] == OS_SEPARATOR
-               || path[0] == OS_SEPARATOR && path[1] == OS_SEPARATOR;
-#endif
-       return rc;
-}
-
-/** Sets the read position of a file.
- * @param file         file to process
- * @param offset       the position. @see <code>whence</code>
- * @param whence       SEEK_SET: offset is absolute (from file's start)
- *                                     SEEK_END: offset is relative to the file' end
- *                                     SEEK_CUR: offset is relative to the current position
- * @return                     0: success<br>
- *                                     otherwise: error code
- */
-int ReFileUtils::seek(FILE* file, int64_t offset, int whence){
-       int rc;
-#if defined __linux__
-       rc = fseeko(file, offset, whence);
-#elif defined __WIN32__
-       rc = _fseek64(file, offset, whence);
-#endif
-       return rc;
-}
-
-/**
- * Returns the current file position.
- *
- * @param file file to process
- * @return     < 0: error occurred<br>
- *                     otherwise: the current read/write position (from the file's start)
- */
-int64_t ReFileUtils::tell(FILE* file)
-{
-       int64_t rc;
-#if defined __linux__
-       rc = ftello(file);
-#elif defined __WIN32__
-       rc = _ftell64(file);
-#endif
-       return rc;
+           m_files(0),
+           m_directories(0),
+           m_fileSizes(0L) {
 }
 
 /**
@@ -111,16 +40,17 @@ int64_t ReFileUtils::tell(FILE* file)
  * @return                     <code>true</code>:  all files deleted<br>
  *                                     <code>false</code>: at least one deletion failed
  */
+
 bool ReFileUtils::deleteTree(const QString& path, bool withBase,
-       ReLogger* logger) {
+    ReLogger* logger) {
        bool rc = true;
        QDir dir(path);
 
        if (dir.exists(path)) {
                QFileInfo info;
                QStringList names = dir.entryList(
-                       QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs
-                               | QDir::Files);
+                   QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs
+                       | QDir::Files);
                QStringList::const_iterator it;
                for (it = names.constBegin(); it != names.constEnd(); ++it) {
                        QString full(path);
@@ -133,16 +63,16 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase,
                                        rc = false;
                                        if (logger != NULL)
                                                logger->logv(LOG_ERROR, LOC_DELETE_TREE_1,
-                                                       "cannot delete directory (%d): %s", errno,
-                                                       full.toUtf8().constData());
+                                                   "cannot delete directory (%d): %s", errno,
+                                                   full.toUtf8().constData());
                                }
                        } else {
                                if (!QFile::remove(full)) {
                                        rc = false;
                                        if (logger != NULL)
                                                logger->logv(LOG_ERROR, LOC_DELETE_TREE_2,
-                                                       "cannot delete file (%d): %s", errno,
-                                                       full.toUtf8().constData());
+                                                   "cannot delete file (%d): %s", errno,
+                                                   full.toUtf8().constData());
                                }
                        }
                }
@@ -150,10 +80,45 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase,
        if (withBase && (rmdir(path.toUtf8())) != 0) {
                rc = false;
                logger->logv(LOG_ERROR, LOC_DELETE_TREE_3,
-                       "cannot delete directory (%d): %s", errno, path.toUtf8());
+                   "cannot delete directory (%d): %s", errno, path.toUtf8());
        }
        return rc;
 }
+/**
+ * Returns whether a path is an absolute path.
+ *
+ * @param path the path to test
+ * @return             <code>true</code>: the path is absolute<br>
+ *                             <code>false</code>: the path is relative
+ */
+bool ReFileUtils::isAbsolutPath(const QString& path) {
+       bool rc;
+#ifdef __linux__
+       rc = path.startsWith(OS_SEPARATOR);
+#else
+       rc = path.length() > 3 && path.at(1) == ':' && path.at(2) == OS_SEPARATOR
+           || path.startsWith("\\\\");
+#endif
+       return rc;
+}
+
+/**
+ * Returns whether a path is an absolute path.
+ *
+ * @param path the path to test
+ * @return             <code>true</code>: the path is absolute<br>
+ *                             <code>false</code>: the path is relative
+ */
+bool ReFileUtils::isAbsolutPath(const char* path) {
+       bool rc;
+#ifdef __linux__
+       rc = path[0] == OS_SEPARATOR;
+#else
+       rc = isalpha(path[0]) && path[1] == ':' && path[2] == OS_SEPARATOR
+           || path[0] == OS_SEPARATOR && path[1] == OS_SEPARATOR;
+#endif
+       return rc;
+}
 
 /**
  * Reads a string from a given file.
@@ -163,7 +128,7 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase,
  * @return              <code>buffer</code> (for chaining)
  */
 QByteArray& ReFileUtils::readFromFile(const char* filename,
-       QByteArray& buffer) {
+    QByteArray& buffer) {
        FILE* fp = fopen(filename, "r");
        if (fp != NULL) {
                struct stat info;
@@ -177,6 +142,75 @@ QByteArray& ReFileUtils::readFromFile(const char* filename,
        return buffer;
 }
 
+/**
+ * Sets the filetimes.
+ *
+ * @param filename     name of the file to change
+ * @param modified     the new modification time
+ * @param accessed     the new access time.
+ *                                     If <code>m_undefinedTime</code> the current time is taken
+ * @return                     <code>true</code>: success
+ */
+bool ReFileUtils::setTimes(const char* filename, const QDateTime& modified,
+    const QDateTime& accessed, ReLogger* logger) {
+       bool rc = true;
+#if defined __linux__
+       struct timeval vals[2];
+       int64_t millisec = accessed == m_undefinedTime
+       ? QDateTime::currentMSecsSinceEpoch() : accessed.toMSecsSinceEpoch();
+       vals[0].tv_sec = millisec / 1000;
+       vals[0].tv_usec = millisec % 1000 * 1000;
+       millisec = modified.toMSecsSinceEpoch();
+       vals[1].tv_sec = millisec / 1000;
+       vals[1].tv_usec = millisec % 1000 * 1000;
+       if (utimes(filename, vals) != 0) {
+               if (logger != NULL)
+               logger->logv(LOG_ERROR, LOC_SET_TIMES_1,
+                       "cannot change times (%d): $s", errno, filename);
+               rc = false;
+       }
+#elif defined __WIN32__
+#error "not implemented"
+#endif
+       return rc;
+}
+
+/** Sets the read position of a file.
+ * @param file         file to process
+ * @param offset       the position. @see <code>whence</code>
+ * @param whence       SEEK_SET: offset is absolute (from file's start)
+ *                                     SEEK_END: offset is relative to the file' end
+ *                                     SEEK_CUR: offset is relative to the current position
+ * @return                     0: success<br>
+ *                                     otherwise: error code
+ */
+int ReFileUtils::seek(FILE* file, int64_t offset, int whence) {
+       int rc;
+#if defined __linux__
+       rc = fseeko(file, offset, whence);
+#elif defined __WIN32__
+       rc = _fseek64(file, offset, whence);
+#endif
+       return rc;
+}
+
+/**
+ * Returns the current file position.
+ *
+ * @param file file to process
+ * @return     < 0: error occurred<br>
+ *                     otherwise: the current read/write position (from the file's start)
+ */
+int64_t ReFileUtils::tell(FILE* file) {
+       int64_t rc;
+#if defined __linux__
+       rc = ftello(file);
+#elif defined __WIN32__
+       rc = _ftell64(file);
+#endif
+       return rc;
+}
+
 /**
  * @brief Returns the name of a directory in the temp dir.
  *
@@ -188,7 +222,7 @@ QByteArray& ReFileUtils::readFromFile(const char* filename,
  * @return              the name of an existing directory
  */
 QByteArray ReFileUtils::tempDir(const char* node, const char* parent,
-       bool withSeparator) {
+    bool withSeparator) {
 #if defined __linux__
        QByteArray temp("/tmp");
        static const char* firstVar = "TMP";
@@ -235,7 +269,7 @@ QByteArray ReFileUtils::tempDir(const char* node, const char* parent,
  * @return                  the full name of a temporary file
  */
 QByteArray ReFileUtils::tempFile(const char* node, const char* parent,
-       bool deleteIfExists) {
+    bool deleteIfExists) {
        QByteArray rc(tempDir(parent));
        if (!rc.endsWith('/'))
                rc += '/';
@@ -256,7 +290,7 @@ QByteArray ReFileUtils::tempFile(const char* node, const char* parent,
  * @param mode          file write mode: "w" (write) or "a" (append)
  */
 void ReFileUtils::writeToFile(const char* filename, const char* content,
-       size_t contentLength, const char* mode) {
+    size_t contentLength, const char* mode) {
        FILE* fp = fopen(filename, mode);
        if (fp != NULL) {
                if (contentLength == (size_t) - 1)
index d27181f18459806738e97539976b6d3f628aa249..ebbc48b2ddd7dc8c51da9af51ecb8b2338501ff4 100644 (file)
@@ -28,18 +28,23 @@ public:
  */
 class ReFileUtils {
 public:
-       static bool deleteTree(const QString& path, bool withBase, ReLogger* logger);
+       static bool deleteTree(const QString& path, bool withBase,
+           ReLogger* logger);
        static bool isAbsolutPath(const QString& path);
        static bool isAbsolutPath(const char* path);
+       static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
        static int seek(FILE* file, int64_t offset, int whence);
+       static bool setTimes(const char* filename, const QDateTime& modified,
+           const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
        static int64_t tell(FILE* file);
        static QByteArray tempDir(const char* node, const char* parent = NULL,
-               bool withSeparator = true);
+           bool withSeparator = true);
        static QByteArray tempFile(const char* node, const char* parent = NULL,
-               bool deleteIfExists = true);
-       static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
+           bool deleteIfExists = true);
        static void writeToFile(const char* filename, const char* content,
-               size_t contentLength = (size_t) - 1, const char* mode = "w");
+           size_t contentLength = (size_t) - 1, const char* mode = "w");
+public:
+       static QDateTime m_undefinedTime;
 };
 
 #endif // REFILEUTILS_HPP
index b32b218a185c08a34ab8af1c0fea43b7df2e3ade..cae8662f75b21023eba6fa8a7c14fef99c88c3f9 100644 (file)
@@ -35,12 +35,12 @@ ReListMatcher* ReListMatcher::m_allMatcher = NULL;
  */
 
 ReMatcher::ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensivity,
-       bool anchored) :
-       m_pattern(),
-               m_needles(),
-               m_restLengths(),
-               m_anchored(anchored),
-               m_caseSensivitiy(caseSensivity) {
+    bool anchored) :
+           m_pattern(),
+           m_needles(),
+           m_restLengths(),
+           m_anchored(anchored),
+           m_caseSensivitiy(caseSensivity) {
        setPattern(pattern, anchored);
 }
 
@@ -53,18 +53,18 @@ ReMatcher::ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensivity,
 bool ReMatcher::matches(const QString& text) {
        bool found = m_allMatching || m_needles.size() == 0;
        int endIx = m_needles.size() - 1;
-       if (! found && m_anchored){
+       if (!found && m_anchored) {
                found = m_needles.at(0).size() == 0
-                               || text.startsWith(m_needles.at(0), m_caseSensivitiy);
-               if (found && (endIx > 0 || text.length() != m_pattern.length())){
+                   || text.startsWith(m_needles.at(0), m_caseSensivitiy);
+               if (found && (endIx > 0 || text.length() != m_pattern.length())) {
                        found = m_needles.at(endIx).size() == 0
-                                       || text.endsWith(m_needles.at(endIx), m_caseSensivitiy);
+                           || text.endsWith(m_needles.at(endIx), m_caseSensivitiy);
                }
        }
-       if (!found || m_anchored && endIx > 1) {
+       if (!found || (m_anchored && endIx > 1)) {
                int startIx = 0;
                int textIndex = 0;
-               if (! m_anchored)
+               if (!m_anchored)
                        found = true;
                else {
                        startIx++;
@@ -74,8 +74,8 @@ bool ReMatcher::matches(const QString& text) {
                for (int ix = startIx; found && ix <= endIx; ix++) {
                        found = text.size() - textIndex >= m_restLengths.at(ix);
                        if (found)
-                               found = (textIndex = text.indexOf(m_needles.at(ix),
-                                                                                                 textIndex, m_caseSensivitiy)) >= 0;
+                               found = (textIndex = text.indexOf(m_needles.at(ix), textIndex,
+                                   m_caseSensivitiy)) >= 0;
                }
        }
        return found;
@@ -117,8 +117,7 @@ void ReMatcher::setPattern(const QString& pattern, bool anchored) {
  *
  * @return     the current pattern
  */
-const QString& ReMatcher::pattern() const
-{
+const QString& ReMatcher::pattern() const {
        return m_pattern;
 }
 
@@ -127,8 +126,7 @@ const QString& ReMatcher::pattern() const
  *
  * @return <code>true</code>: the matcher accepts all strings
  */
-bool ReMatcher::allMatching() const
-{
+bool ReMatcher::allMatching() const {
        return m_allMatching;
 }
 
@@ -137,8 +135,7 @@ bool ReMatcher::allMatching() const
  *
  * @return     <code>true</code>: the character case is relevant
  */
-Qt::CaseSensitivity ReMatcher::caseSensivitiy() const
-{
+Qt::CaseSensitivity ReMatcher::caseSensivitiy() const {
        return m_caseSensivitiy;
 }
 
@@ -147,12 +144,10 @@ Qt::CaseSensitivity ReMatcher::caseSensivitiy() const
  *
  * @param caseSensivitiy       <code>true</code>: the character case is relevant
  */
-void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
-{
+void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy) {
        m_caseSensivitiy = caseSensivitiy;
 }
 
-
 /**
  * Constructor.
  *
@@ -164,18 +159,17 @@ void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
  *                                                     the string
  */
 ReListMatcher::ReListMatcher(const QStringList& patterns,
-                                                        Qt::CaseSensitivity caseSensivity, bool anchored) :
-       m_patterns(patterns),
-       m_list(),
-       m_empty(false),
-       m_allMatching(false)
-{
+    Qt::CaseSensitivity caseSensivity, bool anchored) :
+           m_patterns(patterns),
+           m_list(),
+           m_empty(false),
+           m_allMatching(false) {
        setPatterns(patterns, caseSensivity, anchored);
 }
 /**
 * Destructor.
 */
-ReListMatcher::~ReListMatcher(){
+ * Destructor.
+ */
+ReListMatcher::~ReListMatcher() {
        destroy();
 }
 
@@ -184,8 +178,7 @@ ReListMatcher::~ReListMatcher(){
  *
  * @return <code>true</code>: the matcher accept all strings
  */
-bool ReListMatcher::allMatching() const
-{
+bool ReListMatcher::allMatching() const {
        return m_allMatching;
 }
 
@@ -194,9 +187,8 @@ bool ReListMatcher::allMatching() const
  *
  * @return a
  */
-const QStringList& ReListMatcher::allMatchingList()
-{
-       if (m_allMatchingList == NULL){
+const QStringList& ReListMatcher::allMatchingList() {
+       if (m_allMatchingList == NULL) {
                m_allMatchingList = new QStringList();
                m_allMatchingList->append("*");
        }
@@ -208,16 +200,15 @@ const QStringList& ReListMatcher::allMatchingList()
  *
  * @return     <code>true</code>: the character case is relevant
  */
-Qt::CaseSensitivity ReListMatcher::caseSensivitiy() const
-{
+Qt::CaseSensitivity ReListMatcher::caseSensivitiy() const {
        return m_list.at(0)->caseSensivitiy();
 }
 /**
  * Frees the resources.
  */
-void ReListMatcher::destroy(){
+void ReListMatcher::destroy() {
        QList<ReMatcher*>::const_iterator it;
-       for (it = m_list.constBegin(); it != m_list.cend(); ++it){
+       for (it = m_list.constBegin(); it != m_list.cend(); ++it) {
                delete *it;
        }
        m_list.clear();
@@ -228,22 +219,19 @@ void ReListMatcher::destroy(){
  *
  * @return a matcher accepting all strings
  */
-const ReListMatcher& ReListMatcher::allMatcher()
-{
-       if (m_allMatcher == NULL){
+const ReListMatcher& ReListMatcher::allMatcher() {
+       if (m_allMatcher == NULL) {
                m_allMatcher = new ReListMatcher(allMatchingList());
        }
        return *m_allMatcher;
 }
 
-
 /**
  * Returns the current pattern list.
  *
  * @return the pattern list
  */
-const QStringList& ReListMatcher::patterns() const
-{
+const QStringList& ReListMatcher::patterns() const {
        return m_patterns;
 }
 
@@ -252,8 +240,7 @@ const QStringList& ReListMatcher::patterns() const
  *
  * @return     <code>true</code>: the pattern list is empty
  */
-bool ReListMatcher::empty() const
-{
+bool ReListMatcher::empty() const {
        return m_empty;
 }
 
@@ -265,11 +252,10 @@ bool ReListMatcher::empty() const
  *                             matches the text<br>
  *                             <code>false</code>: none of the patterns matches
  */
-bool ReListMatcher::matches(const QString& text)
-{
+bool ReListMatcher::matches(const QString& text) {
        QList<ReMatcher*>::const_iterator it;
        bool rc = m_list.size() == 0;
-       for (it = m_list.cbegin(); ! rc && it != m_list.cend(); ++it){
+       for (it = m_list.cbegin(); !rc && it != m_list.cend(); ++it) {
                rc = (*it)->matches(text);
        }
        return rc;
@@ -280,10 +266,10 @@ bool ReListMatcher::matches(const QString& text)
  *
  * @param caseSensivitiy       <code>true</code>: the character case is relevant
  */
-void ReListMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
-{
+void ReListMatcher::setCaseSensivitiy(
+    const Qt::CaseSensitivity& caseSensivitiy) {
        QList<ReMatcher*>::const_iterator it;
-       for (it = m_list.begin(); it != m_list.end(); ++it){
+       for (it = m_list.begin(); it != m_list.end(); ++it) {
                (*it)->setCaseSensivitiy(caseSensivitiy);
        }
 }
@@ -296,14 +282,13 @@ void ReListMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
  *                                     <code>false<code>: the pattern can match anywhere
  */
 void ReListMatcher::setPatterns(const QStringList& patterns,
-       Qt::CaseSensitivity caseSensivity, bool anchored)
-{
+    Qt::CaseSensitivity caseSensivity, bool anchored) {
        destroy();
        m_patterns = patterns;
        m_empty = true;
        m_allMatching = false;
        QStringList::const_iterator it;
-       for (it = patterns.constBegin(); it != patterns.cend(); ++it){
+       for (it = patterns.constBegin(); it != patterns.cend(); ++it) {
                ReMatcher* matcher = new ReMatcher(*it, caseSensivity, anchored);
                m_list.append(matcher);
                if (matcher->allMatching())
@@ -312,7 +297,6 @@ void ReListMatcher::setPatterns(const QStringList& patterns,
        }
 }
 
-
 /**
  * Constructor.
  *
@@ -325,11 +309,10 @@ void ReListMatcher::setPatterns(const QStringList& patterns,
  *                                                     the string
  */
 ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QStringList& includes,
-       const QStringList& excludes, Qt::CaseSensitivity caseSensivity,
-       bool anchored) :
-       m_includes(includes, caseSensivity, anchored),
-       m_excludes(excludes, caseSensivity, anchored)
-{
+    const QStringList& excludes, Qt::CaseSensitivity caseSensivity,
+    bool anchored) :
+           m_includes(includes, caseSensivity, anchored),
+           m_excludes(excludes, caseSensivity, anchored) {
 }
 
 /**
@@ -337,8 +320,7 @@ ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QStringList& includes,
  *
  * @return     <code>true</code>: the character case is relevant
  */
-Qt::CaseSensitivity ReIncludeExcludeMatcher::caseSensivitiy() const
-{
+Qt::CaseSensitivity ReIncludeExcludeMatcher::caseSensivitiy() const {
        return m_includes.caseSensivitiy();
 }
 
@@ -346,8 +328,7 @@ Qt::CaseSensitivity ReIncludeExcludeMatcher::caseSensivitiy() const
  * Returns the exclude matcher.
  * @return the exclude matcher
  */
-const ReListMatcher& ReIncludeExcludeMatcher::excludes() const
-{
+const ReListMatcher& ReIncludeExcludeMatcher::excludes() const {
        return m_excludes;
 }
 
@@ -355,8 +336,7 @@ const ReListMatcher& ReIncludeExcludeMatcher::excludes() const
  * Returns the include matcher.
  * @return the include matcher
  */
-const ReListMatcher& ReIncludeExcludeMatcher::includes() const
-{
+const ReListMatcher& ReIncludeExcludeMatcher::includes() const {
        return m_includes;
 }
 
@@ -369,11 +349,10 @@ const ReListMatcher& ReIncludeExcludeMatcher::includes() const
  * @return                             <code>true</code>: at least one of the include patterns
  *                                             matches and none of the exclude patterns matches
  */
-bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo)
-{
+bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo) {
        bool rc = m_includes.matches(text);
-       if (rc && excludeToo && ! m_excludes.empty())
-               rc = ! m_excludes.matches(text);
+       if (rc && excludeToo && !m_excludes.empty())
+               rc = !m_excludes.matches(text);
        return rc;
 }
 
@@ -382,8 +361,8 @@ bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo)
  *
  * @param caseSensivitiy       <code>true</code>: the character case is relevant
  */
-void ReIncludeExcludeMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
-{
+void ReIncludeExcludeMatcher::setCaseSensivitiy(
+    const Qt::CaseSensitivity& caseSensivitiy) {
        m_includes.setCaseSensivitiy(caseSensivitiy);
        m_excludes.setCaseSensivitiy(caseSensivitiy);
 }
index 0c5cb40c0bb82400c0f800813950f61b0a24c12d..e89c8884e89a5fe0b1f34824ceb112f3edea3e1e 100644 (file)
@@ -12,7 +12,6 @@
 #ifndef REMATCHER_HPP
 #define REMATCHER_HPP
 
-
 /**
  * Processor for an efficient test whether a text matches a pattern.
  *
@@ -21,7 +20,7 @@
 class ReMatcher {
 public:
        ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensitivty =
-               Qt::CaseSensitive, bool anchored = false);
+           Qt::CaseSensitive, bool anchored = false);
 public:
        bool allMatching() const;
        Qt::CaseSensitivity caseSensivitiy() const;
@@ -30,7 +29,6 @@ public:
        void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy);
        void setPattern(const QString& pattern, bool anchored = false);
 
-
 protected:
        QString m_pattern;
        QStringList m_needles;
@@ -46,8 +44,9 @@ protected:
  */
 class ReListMatcher {
 public:
-       ReListMatcher(const QStringList& patterns, Qt::CaseSensitivity caseSensitivty =
-                       Qt::CaseSensitive, bool anchored = false);
+       ReListMatcher(const QStringList& patterns,
+           Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored =
+               false);
        ~ReListMatcher();
 public:
        bool allMatching() const;
@@ -57,7 +56,8 @@ public:
        const QStringList& patterns() const;
        void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy);
        void setPatterns(const QStringList& patterns,
-               Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored = false);
+           Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored =
+               false);
 public:
        static const ReListMatcher& allMatcher();
        static const QStringList& allMatchingList();
@@ -77,11 +77,11 @@ protected:
  * Processor for efficient test whether a text matches an include pattern list
  * and not an exclude pattern list.
  */
-class ReIncludeExcludeMatcher{
+class ReIncludeExcludeMatcher {
 public:
-       ReIncludeExcludeMatcher(const QStringList& includes, const QStringList& excludes,
-                       Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive,
-                       bool anchored = false);
+       ReIncludeExcludeMatcher(const QStringList& includes,
+           const QStringList& excludes, Qt::CaseSensitivity caseSensitivty =
+               Qt::CaseSensitive, bool anchored = false);
 public:
        Qt::CaseSensitivity caseSensivitiy() const;
        bool matches(const QString& text, bool excludeToo = true);
index e1cb8b0f8cacd8ea2c8bfd3f242dcdb179c7c270..d605a46af123047e9f58ad2847ae7e35c8b50c96 100644 (file)
@@ -107,7 +107,7 @@ ReString ReQStringUtils::extensionOf(const ReString& filename) {
  *                  otherwise: the length of the integer
  */
 int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix,
-       quint64* pValue) {
+    quint64* pValue) {
        int inputLength = text.size();
        int64_t value = 0;
        int ix = start;
@@ -142,7 +142,7 @@ int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix,
                }
        } else {
                throw ReException("ReQStringUtil::lengthOfInt(): wrong radix: %d",
-                       radix);
+                   radix);
        }
        if (pValue != NULL)
                *pValue = value;
@@ -160,7 +160,7 @@ int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix,
  *                  otherwise: the length of the integer
  */
 int ReQStringUtils::lengthOfUInt(const ReString& text, int start, int radix,
-       uint* pValue) {
+    uint* pValue) {
        quint64 value;
        int rc = lengthOfUInt64(text, start, radix, &value);
        if (pValue != NULL)
@@ -181,7 +181,7 @@ int ReQStringUtils::lengthOfUInt(const ReString& text, int start, int radix,
  *              otherwise: the length of the date in the string
  */
 int ReQStringUtils::lengthOfDate(const ReString& text, int start,
-       QDate* value) {
+    QDate* value) {
        uint day = 0;
        uint month = 0;
        uint year = 0;
@@ -229,7 +229,7 @@ int ReQStringUtils::lengthOfDate(const ReString& text, int start,
                }
        }
        if (day < 1 || day > 31 || month < 1 || month > 12 || year < 1970
-               || year > 2100)
+           || year > 2100)
                length = 0;
        if (length != 0 && value != NULL)
                *value = QDate(year, month, day);
@@ -251,7 +251,7 @@ int ReQStringUtils::lengthOfDate(const ReString& text, int start,
  *                      otherwise: the length of the date in the string
  */
 int ReQStringUtils::lengthOfDateTime(const ReString& text, int start,
-       bool allowDateOnly, bool allowTimeOnly, QDateTime* value) {
+    bool allowDateOnly, bool allowTimeOnly, QDateTime* value) {
        QDate date;
        QTime time;
        int length = lengthOfDate(text, start, &date);
@@ -293,7 +293,7 @@ int ReQStringUtils::lengthOfDateTime(const ReString& text, int start,
  *          otherwise: the length of the date in the string
  */
 int ReQStringUtils::lengthOfTime(const ReString& text, int start,
-       QTime* value) {
+    QTime* value) {
        uint hour = 0;
        uint minute = 0;
        uint sec = 0;
@@ -337,7 +337,7 @@ int ReQStringUtils::lengthOfTime(const ReString& text, int start,
  *                  otherwise: the length of the floating point number
  */
 int ReQStringUtils::lengthOfReal(const ReString& text, int start,
-       qreal* pValue) {
+    qreal* pValue) {
        int inputLength = text.size();
        qreal value = 0.0;
        int cc;
@@ -451,7 +451,7 @@ QString ReQStringUtils::pathAppend(const QString& base, const QString& path) {
  */
 
 QString ReQStringUtils::replaceExtension(const QString& path,
-       const QString& ext) {
+    const QString& ext) {
        QString oldExt = extensionOf(path);
        QString rc;
        if (oldExt.isEmpty())
@@ -472,7 +472,7 @@ QString ReQStringUtils::replaceExtension(const QString& path,
  *                      <code>false</code>: unknown name found (not replaced)
  */
 bool ReQStringUtils::replacePlaceholders(QString& text,
-       const QMap<QString, QString>& placeholders, QString* error) {
+    const QMap<QString, QString>& placeholders, QString* error) {
        int start = 0;
        bool rc = true;
        QString name;
@@ -511,7 +511,7 @@ bool ReQStringUtils::replacePlaceholders(QString& text,
  *                  otherwise: the length is incremented
  */
 void ReQStringUtils::skipExpected(const ReString& text, QChar expected,
-       int& index, int& length) {
+    int& index, int& length) {
        if (length == 0) {
                // error state, do nothing
        } else if (index >= text.length() || text[index] != expected) {
@@ -534,7 +534,7 @@ void ReQStringUtils::skipExpected(const ReString& text, QChar expected,
  * @return              <code>buffer</code>
  */
 char*ReQStringUtils::utf8(const ReString& source, char buffer[],
-       size_t bufferSize) {
+    size_t bufferSize) {
        QByteArray val = source.toUtf8();
        if (val.length() < (int) bufferSize)
                bufferSize = val.length() + 1;
@@ -546,8 +546,8 @@ char*ReQStringUtils::utf8(const ReString& source, char buffer[],
 class ReParserException: public ReException {
 public:
        ReParserException(const QString& message) :
-                       ReException(),
-                       m_message(message) {
+                   ReException(),
+                   m_message(message) {
        }
 public:
        QString m_message;
@@ -560,11 +560,11 @@ public:
  *                   example: "kibyte:1024;kbyte:1000;mibyte:1048576;mbyte:1000000"
  */
 ReUnitParser::ReUnitParser(const QString& expr, const char* unitList,
-       bool parseAtOnce) :
-               m_result(0),
-               m_expr(expr),
-               m_message(),
-               m_unitList(unitList) {
+    bool parseAtOnce) :
+           m_result(0),
+           m_expr(expr),
+           m_message(),
+           m_unitList(unitList) {
        normalize();
        if (parseAtOnce)
                parse();
@@ -633,7 +633,7 @@ void ReUnitParser::normalize() {
        // This makes the syntax easier to parse: only one sum operator ('+').
        for (int ii = m_expr.length() - 1; ii > 0; ii--) {
                if (m_expr[ii] == '-' && m_expr[ii - 1] != '+'
-                       && m_expr[ii - 1] != '*') {
+                   && m_expr[ii - 1] != '*') {
                        m_expr.insert(ii, '+');
                }
        }
@@ -655,8 +655,8 @@ void ReUnitParser::parse() {
                                QStringList powerOperands = it2->split("^");
                                if (powerOperands.count() > 2)
                                        throw ReParserException(
-                                               QObject::tr(
-                                                       "more than 2 power operators, e.g. '2^3^4'"));
+                                           QObject::tr(
+                                               "more than 2 power operators, e.g. '2^3^4'"));
                                QStringList::const_iterator it3 = powerOperands.begin();
                                QString op = *it3;
                                bool isNeg = op.startsWith("-");
@@ -668,8 +668,8 @@ void ReUnitParser::parse() {
                                        uint64_t exponent = valueOf(*++it3);
                                        if (qLn(value) * qLn(exponent) >= qLn(qPow(2.0, 64)))
                                                throw ReParserException(
-                                                       QObject::tr(
-                                                               "number overflow while power operation"));
+                                                   QObject::tr(
+                                                       "number overflow while power operation"));
                                        for (int ii = 1; ii < (int) exponent; ii++)
                                                value = value * fac;
                                }
@@ -708,12 +708,12 @@ uint64_t ReUnitParser::valueOf(const QString& value) const {
                        QStringList pair = it->split(":");
                        if (pair.count() == 0)
                                throw ReParserException(
-                                       QObject::tr(
-                                               "missing ':' in unit definition, e.g. 'k:1000': ")
-                                               + *it);
+                                   QObject::tr(
+                                       "missing ':' in unit definition, e.g. 'k:1000': ")
+                                       + *it);
                        if (pair.count() > 2)
                                throw ReParserException(
-                                       QObject::tr("too many  ':' in unit definition: ") + *it);
+                                   QObject::tr("too many  ':' in unit definition: ") + *it);
                        bool ok = false;
                        QString unit2 = *pair.begin();
                        QString factor = *++pair.begin();
@@ -728,8 +728,8 @@ uint64_t ReUnitParser::valueOf(const QString& value) const {
                }
                if (!found)
                        throw ReParserException(
-                               QObject::tr("unknown unit '$1'. Allowed: ").arg(unit)
-                                       + QString(m_unitList));
+                           QObject::tr("unknown unit '$1'. Allowed: ").arg(unit)
+                               + QString(m_unitList));
        }
        return rc;
 }
@@ -740,10 +740,10 @@ uint64_t ReUnitParser::valueOf(const QString& value) const {
  * @param expr       an expression, e.g. "10*1024kByte+5MiByte"
  */
 ReSizeParser::ReSizeParser(const QString& expr) :
-               ReUnitParser(expr, "byte:1;kbyte:1000;kibyte:1024;"
-                       "mbyte:1000000;mibyte:1048576;"
-                       "gbyte:1000000000;gibyte:1073741824;"
-                       "tbyte:1000000000000;tibyte:1099511627776") {
+           ReUnitParser(expr, "byte:1;kbyte:1000;kibyte:1024;"
+                   "mbyte:1000000;mibyte:1048576;"
+                   "gbyte:1000000000;gibyte:1073741824;"
+                   "tbyte:1000000000000;tibyte:1099511627776") {
 }
 /**
  * Constructor.
@@ -751,7 +751,7 @@ ReSizeParser::ReSizeParser(const QString& expr) :
  * @param expr     an expression, e.g. "3*3days-5min+3weeks"
  */
 ReDateTimeParser::ReDateTimeParser(const QString& expr) :
-               ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", false) {
+           ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", false) {
        parseDateTime(expr);
 }
 
@@ -787,7 +787,7 @@ QDateTime ReDateTimeParser::parseDateTime(const QString& expr) {
                if (m_expr.startsWith("now", Qt::CaseInsensitive)) {
                        m_expr.remove(0, 3);
                } else if ((length2 = ReQStringUtils::lengthOfDateTime(m_expr, 0, true,
-                       true, &dateTime)) > 0) {
+                   true, &dateTime)) > 0) {
                        rc = dateTime;
                        m_expr.remove(0, length2);
                } else {
@@ -807,7 +807,7 @@ QDateTime ReDateTimeParser::parseDateTime(const QString& expr) {
                }
        }
        rc.setMSecsSinceEpoch(
-               isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0);
+           isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0);
        m_dateTime = rc;
        return rc;
 }
index 67d4a984919f73faf66521c36b94b6d9193a9611..e0e4934a183d498abe1d7a0854663a38e69f559f 100644 (file)
@@ -22,18 +22,18 @@ public:
        static QString& ensureLastChar(QString& value, QChar lastChar);
        static ReString extensionOf(const ReString& filename);
        static int lengthOfDate(const ReString& text, int start = 0, QDate* value =
-               NULL);
+           NULL);
        static int lengthOfDateTime(const ReString& text, int start = 0,
-               bool allowDateOnly = true, bool allowTimeOnly = true, QDateTime* value =
-                       NULL);
+           bool allowDateOnly = true, bool allowTimeOnly = true, QDateTime* value =
+               NULL);
        static int lengthOfReal(const ReString& text, int start = 0, qreal* value =
-               NULL);
+           NULL);
        static int lengthOfTime(const ReString& text, int start = 0, QTime* value =
-               NULL);
+           NULL);
        static int lengthOfUInt64(const ReString& text, int start = 0, int radix =
-               10, uint64_t* value = NULL);
+           10, uint64_t* value = NULL);
        static int lengthOfUInt(const ReString& text, int start, int radix,
-               uint* pValue);
+           uint* pValue);
        static bool match(const QString& heap, const QStringList& needles);
        /**
         * Returns the path with native path separators.
@@ -52,9 +52,9 @@ public:
        static QString pathAppend(const QString& base, const QString& path);
        static QString replaceExtension(const QString& path, const QString& ext);
        static bool replacePlaceholders(QString& text,
-               const QMap<QString, QString>& placeholders, QString* error);
+           const QMap<QString, QString>& placeholders, QString* error);
        static void skipExpected(const ReString& text, QChar expected, int& index,
-               int& length);
+           int& length);
        /**
         * @brief Returns the value of a hexadecimal digit.
         *
@@ -64,8 +64,8 @@ public:
         */
        inline static int valueOfHexDigit(int digit) {
                return digit >= '0' && digit <= '9' ? digit - '0' :
-                          digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 :
-                          digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1;
+                      digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 :
+                      digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1;
        }
        static char* utf8(const ReString& source, char buffer[], size_t bufferSize);
 public:
@@ -83,7 +83,7 @@ public:
 class ReUnitParser {
 public:
        ReUnitParser(const QString& expr, const char* unitList, bool parseAtOnce =
-               true);
+           true);
 public:
        bool isValid() const;
        const QString& errorMessage() const;
index 23166873d11c9132d5e96bdac7c8a46705027771..407cb78f9e3ce0c988a07143c85d65e9570ee8f5 100644 (file)
@@ -22,6 +22,7 @@
 
 #ifdef __linux__
 #include <unistd.h>
+#include <sys/time.h>
 #else
 #include <io.h>
 #include <direct.h>
index e1f99dd0ea79911557366f20c786001208ecff46..9f23df3fc16863f1cc746c5ea89facc09c3b6166 100644 (file)
@@ -28,6 +28,8 @@ enum {
        LOC_REMOVE_1,           // 12013
        LOC_REMOVE_2,           // 12014
        LOC_REMOVE_3,           // 12015
+       LOC_SET_PROPERTIES_4,   // 12016
+       LOC_SET_PROPERTIES_5,   // 12017
 };
 
 /**
@@ -36,17 +38,19 @@ enum {
  * @param name the name of the filesystem
  */
 ReFileSystem::ReFileSystem(const QString& name, ReLogger* logger) :
-       m_name(name), m_writeable(false), m_logger(logger), m_buffer(),
-       m_blocksize(4*1024*1024), m_undefinedTime()
-{
+           m_name(name),
+           m_writeable(false),
+           m_logger(logger),
+           m_buffer(),
+           m_blocksize(4 * 1024 * 1024),
+           m_undefinedTime() {
 
 }
 
 /**
  * Destructor.
  */
-ReFileSystem::~ReFileSystem()
-{
+ReFileSystem::~ReFileSystem() {
 }
 
 /**
@@ -58,16 +62,16 @@ ReFileSystem::~ReFileSystem()
  *
  */
 ReFileSystem::ErrorCode ReFileSystem::copy(ReFileMetaData& source,
-               ReFileSystem& sourceFS)
-{
+    ReFileSystem& sourceFS) {
        int blocksize = min(m_blocksize, sourceFS.blocksize());
        ErrorCode rc = EC_SUCCESS;
        ErrorCode rc2;
        int64_t size = 0;
-       while(rc == EC_SUCCESS && size < source.m_size){
-               if ( (rc2 = sourceFS.read(source, size, blocksize, m_buffer)) != EC_SUCCESS)
+       while (rc == EC_SUCCESS && size < source.m_size) {
+               if ((rc2 = sourceFS.read(source, size, blocksize, m_buffer))
+                   != EC_SUCCESS)
                        rc = rc2;
-               else if ( (rc2 = write(source.m_node, size, m_buffer)) != EC_SUCCESS)
+               else if ((rc2 = write(source.m_node, size, m_buffer)) != EC_SUCCESS)
                        rc = rc2;
                size += blocksize;
        }
@@ -82,8 +86,7 @@ ReFileSystem::ErrorCode ReFileSystem::copy(ReFileMetaData& source,
  * @return     <code>true</code>: modification in the filesystem are possible
  *                     <code>false</code>: read only filesystem
  */
-bool ReFileSystem::writeable() const
-{
+bool ReFileSystem::writeable() const {
        return m_writeable;
 }
 
@@ -92,8 +95,7 @@ bool ReFileSystem::writeable() const
  *
  * @param writeable    <code>true</code>: the filesystem is writeable
  */
-void ReFileSystem::setWriteable(bool writeable)
-{
+void ReFileSystem::setWriteable(bool writeable) {
        m_writeable = writeable;
 }
 /**
@@ -101,8 +103,7 @@ void ReFileSystem::setWriteable(bool writeable)
  *
  * @return the current blocksize
  */
-int ReFileSystem::blocksize() const
-{
+int ReFileSystem::blocksize() const {
        return m_blocksize;
 }
 
@@ -114,13 +115,12 @@ int ReFileSystem::blocksize() const
  * @return                     <code>true</code>: at least one file found<br>
  *                                     <code>false</code>: no file found
  */
-bool ReFileSystem::first(const QString& pattern, ReFileMetaData& file)
-{
+bool ReFileSystem::first(const QString& pattern, ReFileMetaData& file) {
        ReFileMetaDataList list;
        QStringList names;
        names.append(pattern);
-       ReIncludeExcludeMatcher matcher(names,
-               ReQStringUtils::m_emptyList, Qt::CaseInsensitive, true);
+       ReIncludeExcludeMatcher matcher(names, ReQStringUtils::m_emptyList,
+           Qt::CaseInsensitive, true);
        listInfos(matcher, list);
        bool rc = list.size() > 0;
        if (rc)
@@ -133,12 +133,10 @@ bool ReFileSystem::first(const QString& pattern, ReFileMetaData& file)
  *
  * @param blocksize    the new blocksize
  */
-void ReFileSystem::setBlocksize(int blocksize)
-{
+void ReFileSystem::setBlocksize(int blocksize) {
        m_blocksize = blocksize;
 }
 
-
 /**
  * Constructor.
  *
@@ -148,21 +146,19 @@ void ReFileSystem::setBlocksize(int blocksize)
  * @param logger
  */
 ReLocalFileSytem::ReLocalFileSytem(const QString& basePath, ReLogger* logger) :
-       ReFileSystem("localfs", logger),
-       m_basePath(basePath),
-       m_currentPath(basePath),
-       m_dir(basePath),
-       m_readFile(NULL),
-       m_writeFile(NULL)
-{
+           ReFileSystem("localfs", logger),
+           m_basePath(basePath),
+           m_currentPath(basePath),
+           m_dir(basePath),
+           m_readFile(NULL),
+           m_writeFile(NULL) {
        setWriteable(true);
 }
 
 /**
  * Destructor.
  */
-ReLocalFileSytem::~ReLocalFileSytem()
-{
+ReLocalFileSytem::~ReLocalFileSytem() {
 
 }
 
@@ -171,21 +167,19 @@ ReLocalFileSytem::~ReLocalFileSytem()
  *
  * @return the base path
  */
-const QString& ReLocalFileSytem::basePath() const
-{
+const QString& ReLocalFileSytem::basePath() const {
        return m_basePath;
 }
 
 /**
  * Closes the open files.
  */
-void ReLocalFileSytem::close()
-{
-       if (m_readFile != NULL){
+void ReLocalFileSytem::close() {
+       if (m_readFile != NULL) {
                fclose(m_readFile);
                m_readFile = NULL;
        }
-       if (m_writeFile != NULL){
+       if (m_writeFile != NULL) {
                fclose(m_writeFile);
                m_writeFile = NULL;
        }
@@ -196,8 +190,7 @@ void ReLocalFileSytem::close()
  *
  * @return     the name of the current directory
  */
-const QString& ReLocalFileSytem::directory() const
-{
+const QString& ReLocalFileSytem::directory() const {
        return m_currentPath;
 }
 
@@ -208,26 +201,25 @@ const QString& ReLocalFileSytem::directory() const
  * @return                     the count of the found entries (<code>list.size()</code>)
  */
 int ReLocalFileSytem::listInfos(const ReIncludeExcludeMatcher& matcher,
-                       ReFileMetaDataList& list)
-{
+    ReFileMetaDataList& list) {
        list.clear();
        const QStringList& patterns = matcher.includes().patterns();
-       QStringList nodes = patterns.size() == 0 ? m_dir.entryList()
-                                                                                  : m_dir.entryList(patterns);
+       QStringList nodes =
+           patterns.size() == 0 ? m_dir.entryList() : m_dir.entryList(patterns);
        QStringList::const_iterator it;
        QByteArray full = m_currentPath.toUtf8();
        full.append(OS_SEPARATOR);
        int pathLength = full.length();
        struct stat info;
-       for (it = nodes.cbegin(); it != nodes.cend(); it++){
+       for (it = nodes.cbegin(); it != nodes.cend(); it++) {
                QString node = *it;
                full.resize(pathLength);
                full.append(node.toUtf8());
-               if (stat(full.constData(), &info) == 0){
-                       list.append(ReFileMetaData(node,
-                                                                          QDateTime::fromTime_t(info.st_mtime),
-                                                                          QDateTime::fromTime_t(info.st_ctime),
-                                                                          info.st_uid, info.st_gid, info.st_mode, info.st_size));
+               if (stat(full.constData(), &info) == 0) {
+                       list.append(
+                           ReFileMetaData(node, QDateTime::fromTime_t(info.st_mtime),
+                               QDateTime::fromTime_t(info.st_ctime), info.st_uid,
+                               info.st_gid, info.st_mode, info.st_size));
                }
        }
        return list.size();
@@ -240,20 +232,18 @@ int ReLocalFileSytem::listInfos(const ReIncludeExcludeMatcher& matcher,
  *                             EC_ALREADY_EXISTS: a file with this name exists<br>
  *                             EC_NOT_ACCESSIBLE: creation failed
  */
-ReFileSystem::ErrorCode ReLocalFileSytem::makeDir(const QString& node)
-{
+ReFileSystem::ErrorCode ReLocalFileSytem::makeDir(const QString& node) {
        ErrorCode rc = EC_SUCCESS;
-       if (! m_writeable){
-               m_logger->log(LOG_ERROR, LOC_MAKE_DIR_1,
-                                         "filesystem is readonly");
+       if (!m_writeable) {
+               m_logger->log(LOG_ERROR, LOC_MAKE_DIR_1, "filesystem is readonly");
                rc = EC_FS_READ_ONLY;
        } else if (m_dir.exists(node)) {
-               m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2,
-                                         "node exists already: %s", fullNameAsUTF8(node).constData());
+               m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2, "node exists already: %s",
+                   fullNameAsUTF8(node).constData());
                rc = EC_ALREADY_EXISTS;
-       } else if (! m_dir.mkdir(node)){
-               m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2,
-                                         "cannot create directory: %s", fullNameAsUTF8(node).constData());
+       } else if (!m_dir.mkdir(node)) {
+               m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2, "cannot create directory: %s",
+                   fullNameAsUTF8(node).constData());
                rc = EC_NOT_ACCESSIBLE;
        }
        return rc;
@@ -267,8 +257,7 @@ ReFileSystem::ErrorCode ReLocalFileSytem::makeDir(const QString& node)
  *                             EC_PATH_NOT_FOUND       directory does not exist<br>
  *                             EC_NOT_ACCESSIBLE       parent not readable
  */
-ReFileSystem::ErrorCode ReLocalFileSytem::setDirectory(const QString& path)
-{
+ReFileSystem::ErrorCode ReLocalFileSytem::setDirectory(const QString& path) {
        ErrorCode rc = m_dir.setCurrent(path) ? EC_SUCCESS : EC_PATH_NOT_FOUND;
        m_currentPath = m_dir.absolutePath();
        return rc;
@@ -286,33 +275,31 @@ ReFileSystem::ErrorCode ReLocalFileSytem::setDirectory(const QString& path)
  *                                     EC_READ: error while reading
  */
 ReFileSystem::ErrorCode ReLocalFileSytem::read(const ReFileMetaData& source,
-                                               int64_t offset, int size, QByteArray& buffer)
-{
+    int64_t offset, int size, QByteArray& buffer) {
        ErrorCode rc = EC_SUCCESS;
-       if (offset == 0){
+       if (offset == 0) {
                if (m_readFile != NULL)
                        fclose(m_readFile);
                QString fn = m_currentPath + source.m_node;
-               if ( (m_readFile = fopen(fn.toUtf8().constData(), "rb")) == NULL){
+               if ((m_readFile = fopen(fn.toUtf8().constData(), "rb")) == NULL) {
                        m_logger->logv(LOG_ERROR, LOC_READ_1,
-                                                 "cannot open for reading (%d): %s",
-                                                 errno, fn.toUtf8().constData());
+                           "cannot open for reading (%d): %s", errno,
+                           fn.toUtf8().constData());
                        rc = EC_NOT_READABLE;
                }
        }
-       if (m_readFile != NULL){
+       if (m_readFile != NULL) {
                ReFileUtils::seek(m_readFile, offset, SEEK_SET);
                buffer.reserve(size);
                int nRead = fread(buffer.data(), 1, size, m_readFile);
-               if (nRead < 0){
-                       m_logger->logv(LOG_ERROR, LOC_READ_2,
-                                                 "cannot read (%d): %s",
-                                                 errno, source.m_node.toUtf8().constData());
+               if (nRead < 0) {
+                       m_logger->logv(LOG_ERROR, LOC_READ_2, "cannot read (%d): %s", errno,
+                           source.m_node.toUtf8().constData());
                        nRead = 0;
                        rc = EC_READ;
                }
                buffer.resize(nRead);
-               if (feof(m_readFile)){
+               if (feof(m_readFile)) {
                        fclose(m_readFile);
                        m_readFile = NULL;
                } else {
@@ -322,59 +309,6 @@ ReFileSystem::ErrorCode ReLocalFileSytem::read(const ReFileMetaData& source,
        return rc;
 }
 
-/**
- * Sets the properties of a file in the current directory.
- *
- * @param source       the properties to copy
- * @param target       the properties of the file to change
- * @return                     EC_SUCCESS: successful<br>
- *                                     EC_FS_READ_ONLY: filesystem is readonly<br>
- *                                     EC_ALREADY_EXISTS: renaming failed: target node exists already<br>
- *                                     EC_RENAME: renaming failed
- *
- */
-ReFileSystem::ErrorCode ReLocalFileSytem::setProperties(
-               const ReFileMetaData& source, const ReFileMetaData& target)
-{
-       ErrorCode rc = EC_SUCCESS;
-       if (! m_writeable){
-               m_logger->log(LOG_ERROR, LOC_SET_PROPERTIES_1,
-                                         "filesystem is readonly");
-               rc = EC_FS_READ_ONLY;
-       } else {
-               if (target.m_node != source.m_node){
-                       if (m_dir.exists(source.m_node)){
-                               rc = EC_ALREADY_EXISTS;
-                               m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_2,
-                                                         "renaming impossible: node exists: %s",
-                                                         fullNameAsUTF8(target.m_node).constData());
-                       } else if (! m_dir.rename(target.m_node, source.m_node)){
-                               rc = EC_RENAME;
-                               m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_3,
-                                                         "renaming impossible: %s -> %s",
-                                                          source.m_node.toUtf8().constData(),
-                                                         fullNameAsUTF8(target.m_node).constData());
-                       }
-               }
-               if (rc == EC_SUCCESS && source.m_modified != target.m_modified
-                               && source.m_modified != m_undefinedTime){
-               }
-               if (rc == EC_SUCCESS && source.m_created != target.m_created
-                               && source.m_created != m_undefinedTime){
-               }
-               if (rc == EC_SUCCESS && source.m_mode != target.m_mode
-                               && source.m_mode != (mode_t) -1){
-               }
-               if (rc == EC_SUCCESS && source.m_owner != target.m_owner
-                               && source.m_owner != -1){
-               }
-               if (rc == EC_SUCCESS && source.m_group != target.m_group
-                               && source.m_group != -1){
-               }
-       }
-       return rc;
-}
-
 /**
  * Removes a file or directory.
  *
@@ -385,28 +319,28 @@ ReFileSystem::ErrorCode ReLocalFileSytem::setProperties(
  *                             EC_NOT_ACCESSIBLE: removing failed
  *
  */
-ReFileSystem::ErrorCode ReLocalFileSytem::remove(const ReFileMetaData& node)
-{
+ReFileSystem::ErrorCode ReLocalFileSytem::remove(const ReFileMetaData& node) {
        ErrorCode rc = EC_SUCCESS;
-       if (! m_writeable){
-               m_logger->log(LOG_ERROR, LOC_REMOVE_1,
-                                         "filesystem is readonly");
+       if (!m_writeable) {
+               m_logger->log(LOG_ERROR, LOC_REMOVE_1, "filesystem is readonly");
                rc = EC_FS_READ_ONLY;
-       } else if (! m_dir.exists(node.m_node)) {
-               m_logger->logv(LOG_ERROR, LOC_REMOVE_2,
-                                         "node does not exists: %s", fullNameAsUTF8(node.m_node).constData());
+       } else if (!m_dir.exists(node.m_node)) {
+               m_logger->logv(LOG_ERROR, LOC_REMOVE_2, "node does not exists: %s",
+                   fullNameAsUTF8(node.m_node).constData());
                rc = EC_NOT_EXISTS;
        } else {
-               if (S_ISDIR(node.m_mode)){
-                       if (! m_dir.rmdir(node.m_node)){
+               if (S_ISDIR(node.m_mode)) {
+                       if (!m_dir.rmdir(node.m_node)) {
                                m_logger->logv(LOG_ERROR, LOC_REMOVE_3,
-                                                         "cannot remove directory: %s", fullNameAsUTF8(node.m_node).constData());
+                                   "cannot remove directory: %s",
+                                   fullNameAsUTF8(node.m_node).constData());
                                rc = EC_NOT_ACCESSIBLE;
                        }
                } else {
-                       if (! m_dir.remove(node.m_node)){
+                       if (!m_dir.remove(node.m_node)) {
                                m_logger->logv(LOG_ERROR, LOC_REMOVE_3,
-                                                         "cannot remove file: %s", fullNameAsUTF8(node.m_node).constData());
+                                   "cannot remove file: %s",
+                                   fullNameAsUTF8(node.m_node).constData());
                                rc = EC_NOT_ACCESSIBLE;
                        }
                }
@@ -414,6 +348,81 @@ ReFileSystem::ErrorCode ReLocalFileSytem::remove(const ReFileMetaData& node)
        return rc;
 }
 
+/**
+ * Sets the properties of a file in the current directory.
+ *
+ * @param source       the properties to copy
+ * @param target       the properties of the file to change
+ * @return                     EC_SUCCESS: successful<br>
+ *                                     EC_FS_READ_ONLY: filesystem is readonly<br>
+ *                                     EC_ALREADY_EXISTS: renaming failed: target node exists already<br>
+ *                                     EC_RENAME: renaming failed
+ *
+ */
+ReFileSystem::ErrorCode ReLocalFileSytem::setProperties(
+    const ReFileMetaData& source, const ReFileMetaData& target) {
+       ErrorCode rc = EC_SUCCESS;
+       if (!m_writeable) {
+               m_logger->log(LOG_ERROR, LOC_SET_PROPERTIES_1,
+                   "filesystem is readonly");
+               rc = EC_FS_READ_ONLY;
+       } else
+               do {
+                       if (target.m_node != source.m_node) {
+                               if (m_dir.exists(source.m_node)) {
+                                       rc = EC_ALREADY_EXISTS;
+                                       m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_2,
+                                           "renaming impossible: node exists: %s",
+                                           fullNameAsUTF8(target.m_node).constData());
+                                       break;
+                               } else if (!m_dir.rename(target.m_node, source.m_node)) {
+                                       rc = EC_RENAME;
+                                       m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_3,
+                                           "renaming impossible: %s -> %s",
+                                           source.m_node.toUtf8().constData(),
+                                           fullNameAsUTF8(target.m_node).constData());
+                                       break;
+                               }
+                       }
+                       QByteArray name;
+                       if (source.m_modified != target.m_modified
+                           && source.m_modified != ReFileUtils::m_undefinedTime) {
+                               if (name.length() == 0)
+                                       name = fullNameAsUTF8(target.m_node);
+                               if (!ReFileUtils::setTimes(name.constData(), source.m_modified,
+                                   ReFileUtils::m_undefinedTime, m_logger))
+                                       rc = EC_NOT_ACCESSIBLE;
+
+                       }
+#ifdef __linux__
+                       if (source.m_mode != target.m_mode
+                               && source.m_mode != (mode_t) -1) {
+                               if (chmod(name.constData(), source.m_mode) != 0) {
+                                       rc = EC_NOT_ACCESSIBLE;
+                                       m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_4,
+                                               "changing permissions is impossible: %s",
+                                               name.constData());}
+                       }
+                       if ( (source.m_owner != target.m_owner
+                                       && source.m_owner != -1)
+                               || (source.m_group != source.m_group
+                                       && source.m_group != -1)) {
+                               int uid = source.m_owner == -1 ? target.m_owner : source.m_owner;
+                               int gid = source.m_group == -1 ? target.m_group : source.m_group;
+                               if (name.length() == 0)
+                               name = fullNameAsUTF8(target.m_node);
+                               if (chown(name.constData(), uid, gid) != 0) {
+                                       rc = EC_NOT_ACCESSIBLE;
+                                       m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_5,
+                                               "changing owner/group is impossible: %s",
+                                               name.constData());
+                               }
+                       }
+#endif
+               } while (false);
+       return rc;
+}
+
 /**
  * Writes a buffer to a file.
  *
@@ -428,40 +437,36 @@ ReFileSystem::ErrorCode ReLocalFileSytem::remove(const ReFileMetaData& node)
  *
  */
 ReFileSystem::ErrorCode ReLocalFileSytem::write(const QString& node,
-                       int64_t offset, const QByteArray& buffer)
-{
+    int64_t offset, const QByteArray& buffer) {
        ErrorCode rc = EC_SUCCESS;
-       if (! writeable()){
-               m_logger->log(LOG_ERROR, LOC_WRITE_1,
-                                         "filesystem is readonly");
+       if (!writeable()) {
+               m_logger->log(LOG_ERROR, LOC_WRITE_1, "filesystem is readonly");
                rc = EC_FS_READ_ONLY;
        } else {
-               if (offset == 0){
+               if (offset == 0) {
                        if (m_writeFile != NULL)
                                fclose(m_writeFile);
                        QString fn = m_currentPath + node;
-                       if ( (m_writeFile = fopen(fn.toUtf8().constData(), "wb")) == NULL){
+                       if ((m_writeFile = fopen(fn.toUtf8().constData(), "wb")) == NULL) {
                                m_logger->logv(LOG_ERROR, LOC_WRITE_2,
-                                                         "cannot open for writing (%d): %s",
-                                                         errno, fn.toUtf8().constData());
+                                   "cannot open for writing (%d): %s", errno,
+                                   fn.toUtf8().constData());
                                rc = EC_NOT_WRITEABLE;
                        }
                }
-               if (m_writeFile != NULL){
+               if (m_writeFile != NULL) {
                        int64_t position = ReFileUtils::tell(m_writeFile);
-                       if (position != offset){
+                       if (position != offset) {
                                rc = EC_POSITION;
                                m_logger->logv(LOG_ERROR, LOC_WRITE_4,
-                                                          "wrong file position: %lld/%lld",
-                                                          offset, position);
+                                   "wrong file position: %lld/%lld", offset, position);
                        } else {
-                               int nWritten = fwrite(buffer.constData(),
-                                                                         1, buffer.length(), m_writeFile);
-                               if (nWritten != buffer.length()){
+                               int nWritten = fwrite(buffer.constData(), 1, buffer.length(),
+                                   m_writeFile);
+                               if (nWritten != buffer.length()) {
                                        m_logger->logv(LOG_ERROR, LOC_WRITE_3,
-                                                                 "cannot write (%d): %s written: %d/%d",
-                                                                 errno, node.toUtf8().constData(),
-                                                                  nWritten, buffer.length());
+                                           "cannot write (%d): %s written: %d/%d", errno,
+                                           node.toUtf8().constData(), nWritten, buffer.length());
                                        rc = EC_WRITE;
                                }
                                fflush(m_writeFile);
@@ -471,12 +476,17 @@ ReFileSystem::ErrorCode ReLocalFileSytem::write(const QString& node,
        return rc;
 }
 
-
 /**
  * Constructor.
  */
-ReFileMetaData::ReFileMetaData() : m_node(), m_modified(), m_created(),
-       m_owner(0), m_group(0), m_mode(0), m_size(-1){
+ReFileMetaData::ReFileMetaData() :
+           m_node(),
+           m_modified(),
+           m_created(),
+           m_owner(-1),
+           m_group(-1),
+           m_mode(-1),
+           m_size(-1) {
 
 }
 
@@ -492,24 +502,21 @@ ReFileMetaData::ReFileMetaData() : m_node(), m_modified(), m_created(),
  * @param size         the filesize (0 for directories)
  */
 ReFileMetaData::ReFileMetaData(const QString& node, const QDateTime& modified,
-               const QDateTime& created, int owner, int group, mode_t mode,
-               int64_t size) :
-       m_node(node),
-       m_modified(modified),
-       m_created(created),
-       m_owner(owner),
-       m_group(group),
-       m_mode(mode),
-       m_size(size)
-{
+    const QDateTime& created, int owner, int group, mode_t mode, int64_t size) :
+           m_node(node),
+           m_modified(modified),
+           m_created(created),
+           m_owner(owner),
+           m_group(group),
+           m_mode(mode),
+           m_size(size) {
 
 }
 
 /**
  * Destructor.
  */
-ReFileMetaData::~ReFileMetaData()
-{
+ReFileMetaData::~ReFileMetaData() {
 
 }
 /**
@@ -518,14 +525,13 @@ ReFileMetaData::~ReFileMetaData()
  * @param source       source to copy
  */
 ReFileMetaData::ReFileMetaData(const ReFileMetaData& source) :
-       m_node(source.m_node),
-       m_modified(source.m_modified),
-       m_created(source.m_created),
-       m_owner(source.m_owner),
-       m_group(source.m_group),
-       m_mode(source.m_mode),
-       m_size(source.m_size)
-{
+           m_node(source.m_node),
+           m_modified(source.m_modified),
+           m_created(source.m_created),
+           m_owner(source.m_owner),
+           m_group(source.m_group),
+           m_mode(source.m_mode),
+           m_size(source.m_size) {
 
 }
 
@@ -535,8 +541,7 @@ ReFileMetaData::ReFileMetaData(const ReFileMetaData& source) :
  * @param source       source to copy
  * @return                     the instance itself
  */
-ReFileMetaData&ReFileMetaData::operator =(const ReFileMetaData& source)
-{
+ReFileMetaData&ReFileMetaData::operator =(const ReFileMetaData& source) {
        m_node = source.m_node;
        m_modified = source.m_modified;
        m_created = source.m_created;
index c0cf4d5c92d3177453733c6a40b13a8cf78ecb5b..cfaee4b9fe665c6347cdd49aa0b2476119af9d24 100644 (file)
@@ -16,8 +16,8 @@ class ReFileMetaData {
 public:
        ReFileMetaData();
        ReFileMetaData(const QString& node, const QDateTime& modified,
-               const QDateTime& created,
-               int owner, int group, mode_t mode, int64_t size);
+           const QDateTime& created, int owner, int group, mode_t mode,
+           int64_t size);
        virtual ~ReFileMetaData();
        ReFileMetaData(const ReFileMetaData& source);
        ReFileMetaData& operator =(const ReFileMetaData& source);
@@ -73,7 +73,7 @@ public:
         * @return                      the count of the found entries (<code>list.size()</code>)
         */
        virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
-                                                 ReFileMetaDataList& list) = 0;
+           ReFileMetaDataList& list) = 0;
        /** Creates a directory.
         * @param node  the name without path (in the current directory)
         * @return              EC_SUCCESS or error code
@@ -86,9 +86,8 @@ public:
         * @param buffer        OUT: content of the file
         * @return                      EC_SUCCESS or error code
         */
-       virtual ErrorCode read(const ReFileMetaData& source,
-                                                  int64_t offset, int size,
-                                                  QByteArray& buffer) = 0;
+       virtual ErrorCode read(const ReFileMetaData& source, int64_t offset,
+           int size, QByteArray& buffer) = 0;
        /** Removes a file or directory.
         * @param node  the properties ot the node (in the current directory)
         * @return              EC_SUCCESS or error code
@@ -106,15 +105,15 @@ public:
         * @return              EC_SUCCESS or error code
         */
        virtual ErrorCode setProperties(const ReFileMetaData& source,
-                                                                       const ReFileMetaData& target) = 0;
+           const ReFileMetaData& target) = 0;
        /** Writes a buffer to a file.
         * @param node          the file to write (without path, inside the current directory)
         * @param offset        first position to write
         * @param buffer        content to write
         * @return                      EC_SUCCESS or error code
         */
-       virtual ErrorCode write(const QString& target,
-                                                  int64_t offset, const QByteArray& buffer) = 0;
+       virtual ErrorCode write(const QString& target, int64_t offset,
+           const QByteArray& buffer) = 0;
 public:
        virtual ErrorCode copy(ReFileMetaData& source, ReFileSystem& sourceFS);
 public:
@@ -124,14 +123,14 @@ public:
         * @param node  the name without path
         * @return              the full filename
         */
-       inline QString fullName(const QString& node) const{
+       inline QString fullName(const QString& node) const {
                return m_directory + node;
        }
        /** Returns the full name (with path) as UTF-8 string.
         * @param node  the name without path
         * @return              the full filename
         */
-       QByteArray fullNameAsUTF8(const QString& node) const{
+       QByteArray fullNameAsUTF8(const QString& node) const {
                return (m_directory + node).toUtf8();
        }
        void setWriteable(bool writeable);
@@ -148,7 +147,7 @@ protected:
        QDateTime m_undefinedTime;
 };
 
-class ReLocalFileSytem : public ReFileSystem {
+class ReLocalFileSytem: public ReFileSystem {
 public:
        ReLocalFileSytem(const QString& basePath, ReLogger* logger);
        virtual ~ReLocalFileSytem();
@@ -161,14 +160,15 @@ public:
        // ReFileSystem interface
        virtual void close();
        virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
-                                                 ReFileMetaDataList& list);
+           ReFileMetaDataList& list);
        ErrorCode makeDir(const QString& node);
        virtual ErrorCode read(const ReFileMetaData& source, int64_t offset,
-                                                  int size, QByteArray& buffer);
+           int size, QByteArray& buffer);
        ErrorCode remove(const ReFileMetaData& node);
-       ErrorCode setProperties(const ReFileMetaData& source, const ReFileMetaData& target);
+       ErrorCode setProperties(const ReFileMetaData& source,
+           const ReFileMetaData& target);
        virtual ErrorCode write(const QString& target, int64_t offset,
-                                                       const QByteArray& buffer);
+           const QByteArray& buffer);
 
 protected:
        QString m_basePath;