diff options
-rw-r--r-- | src/common/syncjournaldb.cpp | 4 | ||||
-rw-r--r-- | src/common/syncjournalfilerecord.cpp | 2 | ||||
-rw-r--r-- | src/common/syncjournalfilerecord.h | 3 | ||||
-rw-r--r-- | src/csync/csync.cpp | 17 | ||||
-rw-r--r-- | src/csync/csync.h | 37 | ||||
-rw-r--r-- | src/csync/csync_exclude.cpp | 18 | ||||
-rw-r--r-- | src/csync/csync_exclude.h | 8 | ||||
-rw-r--r-- | src/csync/csync_private.h | 2 | ||||
-rw-r--r-- | src/csync/csync_reconcile.cpp | 12 | ||||
-rw-r--r-- | src/csync/csync_update.cpp | 32 | ||||
-rw-r--r-- | src/csync/vio/csync_vio_local_unix.cpp | 14 | ||||
-rw-r--r-- | src/csync/vio/csync_vio_local_win.cpp | 12 | ||||
-rw-r--r-- | src/libsync/discoveryphase.cpp | 4 | ||||
-rw-r--r-- | src/libsync/syncengine.cpp | 20 | ||||
-rw-r--r-- | src/libsync/syncfileitem.cpp | 2 | ||||
-rw-r--r-- | src/libsync/syncfileitem.h | 13 | ||||
-rw-r--r-- | test/csync/csync_tests/check_csync_exclude.cpp | 8 | ||||
-rw-r--r-- | test/csync/csync_tests/check_csync_update.cpp | 2 | ||||
-rw-r--r-- | test/csync/vio_tests/check_vio_ext.cpp | 2 | ||||
-rw-r--r-- | test/testsyncjournaldb.cpp | 4 |
20 files changed, 104 insertions, 112 deletions
diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index fa609089e..b2d348af8 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -47,7 +47,7 @@ static void fillFileRecordFromGetQuery(SyncJournalFileRecord &rec, SqlQuery &que rec._path = query.baValue(0); rec._inode = query.int64Value(1); rec._modtime = query.int64Value(2); - rec._type = query.intValue(3); + rec._type = static_cast<ItemType>(query.intValue(3)); rec._etag = query.baValue(4); rec._fileId = query.baValue(5); rec._remotePerm = RemotePermissions(query.baValue(6).constData()); @@ -1840,7 +1840,7 @@ void SyncJournalDb::avoidReadFromDbOnNextSync(const QByteArray &fileName) SqlQuery query(_db); // This query will match entries for which the path is a prefix of fileName - // Note: CSYNC_FTW_TYPE_DIR == 2 + // Note: ItemTypeDirectory == 2 query.prepare("UPDATE metadata SET md5='_invalid_' WHERE ?1 LIKE(path||'/%') AND type == 2;"); query.bindValue(1, fileName); query.exec(); diff --git a/src/common/syncjournalfilerecord.cpp b/src/common/syncjournalfilerecord.cpp index 226c25d6c..607d2e6db 100644 --- a/src/common/syncjournalfilerecord.cpp +++ b/src/common/syncjournalfilerecord.cpp @@ -23,7 +23,7 @@ namespace OCC { SyncJournalFileRecord::SyncJournalFileRecord() : _inode(0) - , _type(0) + , _type(ItemTypeSkip) , _fileSize(0) , _serverHasIgnoredFiles(false) { diff --git a/src/common/syncjournalfilerecord.h b/src/common/syncjournalfilerecord.h index bc34ef135..76fd4cdbe 100644 --- a/src/common/syncjournalfilerecord.h +++ b/src/common/syncjournalfilerecord.h @@ -22,6 +22,7 @@ #include <QString> #include <QDateTime> +#include "csync.h" #include "ocsynclib.h" #include "remotepermissions.h" #include "common/utility.h" @@ -56,7 +57,7 @@ public: QByteArray _path; quint64 _inode; qint64 _modtime; - int _type; + ItemType _type; QByteArray _etag; QByteArray _fileId; qint64 _fileSize; diff --git a/src/csync/csync.cpp b/src/csync/csync.cpp index f80d4d4d2..fdbe5886f 100644 --- a/src/csync/csync.cpp +++ b/src/csync/csync.cpp @@ -49,6 +49,7 @@ #include "csync_log.h" #include "csync_rename.h" #include "common/c_jhash.h" +#include "common/syncjournalfilerecord.h" csync_s::csync_s(const char *localUri, OCC::SyncJournalDb *statedb) @@ -402,3 +403,19 @@ int csync_abort_requested(CSYNC *ctx) return (1 == 0); } } + +std::unique_ptr<csync_file_stat_t> csync_file_stat_s::fromSyncJournalFileRecord(const OCC::SyncJournalFileRecord &rec) +{ + std::unique_ptr<csync_file_stat_t> st(new csync_file_stat_t); + st->path = rec._path; + st->inode = rec._inode; + st->modtime = rec._modtime; + st->type = static_cast<ItemType>(rec._type); + st->etag = rec._etag; + st->file_id = rec._fileId; + st->remotePerm = rec._remotePerm; + st->size = rec._fileSize; + st->has_ignored_files = rec._serverHasIgnoredFiles; + st->checksumHeader = rec._checksumHeader; + return st; +} diff --git a/src/csync/csync.h b/src/csync/csync.h index 753688cdb..3a1d8d584 100644 --- a/src/csync/csync.h +++ b/src/csync/csync.h @@ -34,7 +34,6 @@ #include "std/c_private.h" #include "ocsynclib.h" -#include "common/syncjournalfilerecord.h" #include <sys/stat.h> #include <stdbool.h> @@ -45,6 +44,10 @@ #include <QByteArray> #include "common/remotepermissions.h" +namespace OCC { +class SyncJournalFileRecord; +} + #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) && (__GNUC__ * 100 + __GNUC_MINOR__ < 408) // openSuse 12.3 didn't like enum bitfields. #define BITFIELD(size) @@ -151,11 +154,13 @@ enum csync_instructions_e { but without any propagation (UPDATE|RECONCILE) */ }; -enum csync_ftw_type_e { - CSYNC_FTW_TYPE_FILE, - CSYNC_FTW_TYPE_SLINK, - CSYNC_FTW_TYPE_DIR, - CSYNC_FTW_TYPE_SKIP +// This enum is used with BITFIELD(3) and BITFIELD(4) in several places. +// Also, this value is stored in the database, so beware of value changes. +enum ItemType { + ItemTypeFile = 0, + ItemTypeSoftLink = 1, + ItemTypeDirectory = 2, + ItemTypeSkip = 3 }; @@ -172,7 +177,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { uint64_t inode; OCC::RemotePermissions remotePerm; - enum csync_ftw_type_e type BITFIELD(4); + ItemType type BITFIELD(4); bool child_modified BITFIELD(1); bool has_ignored_files BITFIELD(1); // Specify that a directory, or child directory contains ignored files. bool is_hidden BITFIELD(1); // Not saved in the DB, only used during discovery for local files. @@ -199,7 +204,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { : modtime(0) , size(0) , inode(0) - , type(CSYNC_FTW_TYPE_SKIP) + , type(ItemTypeSkip) , child_modified(false) , has_ignored_files(false) , is_hidden(false) @@ -207,21 +212,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { , instruction(CSYNC_INSTRUCTION_NONE) { } - static std::unique_ptr<csync_file_stat_t> fromSyncJournalFileRecord(const OCC::SyncJournalFileRecord &rec) - { - std::unique_ptr<csync_file_stat_t> st(new csync_file_stat_t); - st->path = rec._path; - st->inode = rec._inode; - st->modtime = rec._modtime; - st->type = static_cast<csync_ftw_type_e>(rec._type); - st->etag = rec._etag; - st->file_id = rec._fileId; - st->remotePerm = rec._remotePerm; - st->size = rec._fileSize; - st->has_ignored_files = rec._serverHasIgnoredFiles; - st->checksumHeader = rec._checksumHeader; - return st; - } + static std::unique_ptr<csync_file_stat_t> fromSyncJournalFileRecord(const OCC::SyncJournalFileRecord &rec); }; /** diff --git a/src/csync/csync_exclude.cpp b/src/csync/csync_exclude.cpp index c090b1f1a..762a8eae4 100644 --- a/src/csync/csync_exclude.cpp +++ b/src/csync/csync_exclude.cpp @@ -393,9 +393,9 @@ bool ExcludedFiles::isExcluded( } QFileInfo fi(filePath); - csync_ftw_type_e type = CSYNC_FTW_TYPE_FILE; + ItemType type = ItemTypeFile; if (fi.isDir()) { - type = CSYNC_FTW_TYPE_DIR; + type = ItemTypeDirectory; } QString relativePath = filePath.mid(basePath.size()); @@ -406,7 +406,7 @@ bool ExcludedFiles::isExcluded( return fullPatternMatch(relativePath.toUtf8(), type) != CSYNC_NOT_EXCLUDED; } -CSYNC_EXCLUDE_TYPE ExcludedFiles::traversalPatternMatch(const char *path, int filetype) const +CSYNC_EXCLUDE_TYPE ExcludedFiles::traversalPatternMatch(const char *path, ItemType filetype) const { auto match = _csync_excluded_common(path); if (match != CSYNC_NOT_EXCLUDED) @@ -426,7 +426,7 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::traversalPatternMatch(const char *path, int fi QString bnameStr = QString::fromUtf8(bname); QRegularExpressionMatch m; - if (filetype == CSYNC_FTW_TYPE_DIR) { + if (filetype == ItemTypeDirectory) { m = _bnameActivationRegexDir.match(bnameStr); } else { m = _bnameActivationRegexFile.match(bnameStr); @@ -437,7 +437,7 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::traversalPatternMatch(const char *path, int fi // Now run the full match QString pathStr = QString::fromUtf8(path); - if (filetype == CSYNC_FTW_TYPE_DIR) { + if (filetype == ItemTypeDirectory) { m = _fullRegexDir.match(pathStr); } else { m = _fullRegexFile.match(pathStr); @@ -452,7 +452,7 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::traversalPatternMatch(const char *path, int fi return match; } -CSYNC_EXCLUDE_TYPE ExcludedFiles::fullPatternMatch(const char *path, int filetype) const +CSYNC_EXCLUDE_TYPE ExcludedFiles::fullPatternMatch(const char *path, ItemType filetype) const { auto match = _csync_excluded_common(path); if (match != CSYNC_NOT_EXCLUDED) @@ -462,7 +462,7 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::fullPatternMatch(const char *path, int filetyp QString p = QString::fromUtf8(path); QRegularExpressionMatch m; - if (filetype == CSYNC_FTW_TYPE_DIR) { + if (filetype == ItemTypeDirectory) { m = _fullRegexDir.match(p); } else { m = _fullRegexFile.match(p); @@ -478,9 +478,9 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::fullPatternMatch(const char *path, int filetyp } auto ExcludedFiles::csyncTraversalMatchFun() const - -> std::function<CSYNC_EXCLUDE_TYPE(const char *path, int filetype)> + -> std::function<CSYNC_EXCLUDE_TYPE(const char *path, ItemType filetype)> { - return [this](const char *path, int filetype) { return this->traversalPatternMatch(path, filetype); }; + return [this](const char *path, ItemType filetype) { return this->traversalPatternMatch(path, filetype); }; } static QString convertToRegexpSyntax(QString exclude) diff --git a/src/csync/csync_exclude.h b/src/csync/csync_exclude.h index f2c14a767..9f1c544d7 100644 --- a/src/csync/csync_exclude.h +++ b/src/csync/csync_exclude.h @@ -30,6 +30,8 @@ #include <QString> #include <QRegularExpression> +#include <functional> + enum csync_exclude_type_e { CSYNC_NOT_EXCLUDED = 0, CSYNC_FILE_SILENTLY_EXCLUDED, @@ -108,7 +110,7 @@ public: * ExcludedFiles instance stays alive. */ auto csyncTraversalMatchFun() const - -> std::function<CSYNC_EXCLUDE_TYPE(const char *path, int filetype)>; + -> std::function<CSYNC_EXCLUDE_TYPE(const char *path, ItemType filetype)>; public slots: /** @@ -125,7 +127,7 @@ private: * Note that this only matches patterns. It does not check whether the file * or directory pointed to is hidden (or whether it even exists). */ - CSYNC_EXCLUDE_TYPE fullPatternMatch(const char *path, int filetype) const; + CSYNC_EXCLUDE_TYPE fullPatternMatch(const char *path, ItemType filetype) const; /** * @brief Check if the given path should be excluded in a traversal situation. @@ -142,7 +144,7 @@ private: * Note that this only matches patterns. It does not check whether the file * or directory pointed to is hidden (or whether it even exists). */ - CSYNC_EXCLUDE_TYPE traversalPatternMatch(const char *path, int filetype) const; + CSYNC_EXCLUDE_TYPE traversalPatternMatch(const char *path, ItemType filetype) const; /** * Generate optimized regular expressions for the exclude patterns. diff --git a/src/csync/csync_private.h b/src/csync/csync_private.h index e692e7ba1..9a0276507 100644 --- a/src/csync/csync_private.h +++ b/src/csync/csync_private.h @@ -153,7 +153,7 @@ struct OCSYNC_EXPORT csync_s { * * See ExcludedFiles in csync_exclude. */ - std::function<CSYNC_EXCLUDE_TYPE(const char *path, int filetype)> exclude_traversal_fn; + std::function<CSYNC_EXCLUDE_TYPE(const char *path, ItemType filetype)> exclude_traversal_fn; struct { std::unordered_map<ByteArrayRef, QByteArray, ByteArrayRefHash> folder_renamed_to; // map from->to diff --git a/src/csync/csync_reconcile.cpp b/src/csync/csync_reconcile.cpp index daad534ae..f7e30785e 100644 --- a/src/csync/csync_reconcile.cpp +++ b/src/csync/csync_reconcile.cpp @@ -178,7 +178,7 @@ static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) { // other is found as well? qCDebug(lcReconcile, "Other has already been renamed to %s", other->rename_path.constData()); - } else if (cur->type == CSYNC_FTW_TYPE_DIR + } else if (cur->type == ItemTypeDirectory // The local replica is reconciled first, so the remote tree would // have either NONE or UPDATE_METADATA if the remote file is safe to // move. @@ -297,8 +297,8 @@ static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) { /* file on other replica is changed or new */ case CSYNC_INSTRUCTION_NEW: case CSYNC_INSTRUCTION_EVAL: - if (other->type == CSYNC_FTW_TYPE_DIR && - cur->type == CSYNC_FTW_TYPE_DIR) { + if (other->type == ItemTypeDirectory && + cur->type == ItemTypeDirectory) { // Folders of the same path are always considered equals is_conflict = false; } else { @@ -375,7 +375,7 @@ static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) { // needs to delete the other entity first. cur->instruction = CSYNC_INSTRUCTION_TYPE_CHANGE; other->instruction = CSYNC_INSTRUCTION_NONE; - } else if (cur->type == CSYNC_FTW_TYPE_DIR) { + } else if (cur->type == ItemTypeDirectory) { cur->instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; other->instruction = CSYNC_INSTRUCTION_NONE; } else { @@ -408,7 +408,7 @@ static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) { const char *repo = ctx->current == REMOTE_REPLICA ? "server" : "client"; if(cur->instruction ==CSYNC_INSTRUCTION_NONE) { - if(cur->type == CSYNC_FTW_TYPE_DIR) + if(cur->type == ItemTypeDirectory) { qCDebug(lcReconcile, "%-30s %s dir: %s", @@ -427,7 +427,7 @@ static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) { } else { - if(cur->type == CSYNC_FTW_TYPE_DIR) + if(cur->type == ItemTypeDirectory) { qCInfo(lcReconcile, "%-30s %s dir: %s", diff --git a/src/csync/csync_update.cpp b/src/csync/csync_update.cpp index ae7efba77..ad58ef5b6 100644 --- a/src/csync/csync_update.cpp +++ b/src/csync/csync_update.cpp @@ -117,7 +117,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f return -1; } - if (fs->type == CSYNC_FTW_TYPE_SKIP) { + if (fs->type == ItemTypeSkip) { excluded =CSYNC_FILE_EXCLUDE_STAT_FAILED; } else { /* Check if file is excluded */ @@ -159,13 +159,13 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f } } - if (fs->type == CSYNC_FTW_TYPE_FILE ) { + if (fs->type == ItemTypeFile ) { if (fs->modtime == 0) { qCDebug(lcUpdate, "file: %s - mtime is zero!", fs->path.constData()); } } - if (excluded > CSYNC_NOT_EXCLUDED || fs->type == CSYNC_FTW_TYPE_SLINK) { + if (excluded > CSYNC_NOT_EXCLUDED || fs->type == ItemTypeSoftLink) { fs->instruction = CSYNC_INSTRUCTION_IGNORE; if (ctx->current_fs) { ctx->current_fs->has_ignored_files = true; @@ -238,7 +238,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f bool metadata_differ = (ctx->current == REMOTE_REPLICA && (fs->file_id != base._fileId || fs->remotePerm != base._remotePerm)) || (ctx->current == LOCAL_REPLICA && fs->inode != base._inode); - if (fs->type == CSYNC_FTW_TYPE_DIR && ctx->current == REMOTE_REPLICA + if (fs->type == ItemTypeDirectory && ctx->current == REMOTE_REPLICA && !metadata_differ && ctx->read_remote_from_db) { /* If both etag and file id are equal for a directory, read all contents from * the database. @@ -277,7 +277,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f bool isRename = base.isValid() && base._type == fs->type - && ((base._modtime == fs->modtime && base._fileSize == fs->size) || fs->type == CSYNC_FTW_TYPE_DIR) + && ((base._modtime == fs->modtime && base._fileSize == fs->size) || fs->type == ItemTypeDirectory) #ifdef NO_RENAME_EXTENSION && _csync_sameextension(base._path, fs->path) #endif @@ -286,7 +286,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f // Verify the checksum where possible if (isRename && !base._checksumHeader.isEmpty() && ctx->callbacks.checksum_hook - && fs->type == CSYNC_FTW_TYPE_FILE) { + && fs->type == ItemTypeFile) { fs->checksumHeader = ctx->callbacks.checksum_hook( _rel_to_abs(ctx, fs->path), base._checksumHeader, ctx->callbacks.checksum_userdata); @@ -300,7 +300,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f qCDebug(lcUpdate, "pot rename detected based on inode # %" PRId64 "", (uint64_t) fs->inode); /* inode found so the file has been renamed */ fs->instruction = CSYNC_INSTRUCTION_EVAL_RENAME; - if (fs->type == CSYNC_FTW_TYPE_DIR) { + if (fs->type == ItemTypeDirectory) { csync_rename_record(ctx, base._path, fs->path); } } @@ -325,7 +325,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f done = true; return; } - if (fs->type != CSYNC_FTW_TYPE_DIR && base._etag != fs->etag) { + if (fs->type != ItemTypeDirectory && base._etag != fs->etag) { /* File with different etag, don't do a rename, but download the file again */ qCWarning(lcUpdate, "file etag different, not a rename"); done = true; @@ -333,7 +333,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f } // Record directory renames - if (fs->type == CSYNC_FTW_TYPE_DIR) { + if (fs->type == ItemTypeDirectory) { // If the same folder was already renamed by a different entry, // skip to the next candidate if (ctx->renames.folder_renamed_to.count(base._path) > 0) { @@ -354,7 +354,7 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f } if (fs->instruction == CSYNC_INSTRUCTION_NEW - && fs->type == CSYNC_FTW_TYPE_DIR + && fs->type == ItemTypeDirectory && ctx->current == REMOTE_REPLICA && ctx->callbacks.checkSelectiveSyncNewFolderHook) { if (ctx->callbacks.checkSelectiveSyncNewFolderHook(ctx->callbacks.update_callback_userdata, fs->path, fs->remotePerm)) { @@ -369,7 +369,7 @@ out: /* Set the ignored error string. */ if (fs->instruction == CSYNC_INSTRUCTION_IGNORE) { - if( fs->type == CSYNC_FTW_TYPE_SLINK ) { + if( fs->type == ItemTypeSoftLink ) { fs->error_status = CSYNC_STATUS_INDIVIDUAL_IS_SYMLINK; /* Symbolic links are ignored. */ } else { if (excluded == CSYNC_FILE_EXCLUDE_LIST) { @@ -394,7 +394,7 @@ out: if (fs->instruction != CSYNC_INSTRUCTION_NONE && fs->instruction != CSYNC_INSTRUCTION_IGNORE && fs->instruction != CSYNC_INSTRUCTION_UPDATE_METADATA - && fs->type != CSYNC_FTW_TYPE_DIR) { + && fs->type != ItemTypeDirectory) { fs->child_modified = true; } @@ -436,21 +436,21 @@ int csync_walker(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> fs) { } switch (fs->type) { - case CSYNC_FTW_TYPE_FILE: + case ItemTypeFile: if (ctx->current == REMOTE_REPLICA) { qCDebug(lcUpdate, "file: %s [file_id=%s size=%" PRIu64 "]", fs->path.constData(), fs->file_id.constData(), fs->size); } else { qCDebug(lcUpdate, "file: %s [inode=%" PRIu64 " size=%" PRIu64 "]", fs->path.constData(), fs->inode, fs->size); } break; - case CSYNC_FTW_TYPE_DIR: /* enter directory */ + case ItemTypeDirectory: /* enter directory */ if (ctx->current == REMOTE_REPLICA) { qCDebug(lcUpdate, "directory: %s [file_id=%s]", fs->path.constData(), fs->file_id.constData()); } else { qCDebug(lcUpdate, "directory: %s [inode=%" PRIu64 "]", fs->path.constData(), fs->inode); } break; - case CSYNC_FTW_TYPE_SLINK: + case ItemTypeSoftLink: qCDebug(lcUpdate, "symlink: %s - not supported", fs->path.constData()); break; default: @@ -690,7 +690,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, } previous_fs = ctx->current_fs; - bool recurse = dirent->type == CSYNC_FTW_TYPE_DIR; + bool recurse = dirent->type == ItemTypeDirectory; /* Call walker function for each file */ rc = fn(ctx, std::move(dirent)); diff --git a/src/csync/vio/csync_vio_local_unix.cpp b/src/csync/vio/csync_vio_local_unix.cpp index b60fe99ce..c65e21d9f 100644 --- a/src/csync/vio/csync_vio_local_unix.cpp +++ b/src/csync/vio/csync_vio_local_unix.cpp @@ -120,9 +120,9 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *d case DT_DIR: case DT_REG: if (dirent->d_type == DT_DIR) { - file_stat->type = CSYNC_FTW_TYPE_DIR; + file_stat->type = ItemTypeDirectory; } else { - file_stat->type = CSYNC_FTW_TYPE_FILE; + file_stat->type = ItemTypeFile; } break; default: @@ -135,7 +135,7 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *d if (_csync_vio_local_stat_mb(fullPath.constData(), file_stat.get()) < 0) { // Will get excluded by _csync_detect_update. - file_stat->type = CSYNC_FTW_TYPE_SKIP; + file_stat->type = ItemTypeSkip; } return file_stat; } @@ -160,17 +160,17 @@ static int _csync_vio_local_stat_mb(const mbchar_t *wuri, csync_file_stat_t *buf switch (sb.st_mode & S_IFMT) { case S_IFDIR: - buf->type = CSYNC_FTW_TYPE_DIR; + buf->type = ItemTypeDirectory; break; case S_IFREG: - buf->type = CSYNC_FTW_TYPE_FILE; + buf->type = ItemTypeFile; break; case S_IFLNK: case S_IFSOCK: - buf->type = CSYNC_FTW_TYPE_SLINK; + buf->type = ItemTypeSoftLink; break; default: - buf->type = CSYNC_FTW_TYPE_SKIP; + buf->type = ItemTypeSkip; break; } diff --git a/src/csync/vio/csync_vio_local_win.cpp b/src/csync/vio/csync_vio_local_win.cpp index 588575ed1..3b94550bb 100644 --- a/src/csync/vio/csync_vio_local_win.cpp +++ b/src/csync/vio/csync_vio_local_win.cpp @@ -172,21 +172,21 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *d // Detect symlinks, and treat junctions as symlinks too. if (handle->ffd.dwReserved0 == IO_REPARSE_TAG_SYMLINK || handle->ffd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT) { - file_stat->type = CSYNC_FTW_TYPE_SLINK; + file_stat->type = ItemTypeSoftLink; } else { // The SIS and DEDUP reparse points should be treated as // regular files. We don't know about the other ones yet, // but will also treat them normally for now. - file_stat->type = CSYNC_FTW_TYPE_FILE; + file_stat->type = ItemTypeFile; } } else if (handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE || handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE || handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) { - file_stat->type = CSYNC_FTW_TYPE_SKIP; + file_stat->type = ItemTypeSkip; } else if (handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - file_stat->type = CSYNC_FTW_TYPE_DIR; + file_stat->type = ItemTypeDirectory; } else { - file_stat->type = CSYNC_FTW_TYPE_FILE; + file_stat->type = ItemTypeFile; } /* Check for the hidden flag */ @@ -204,7 +204,7 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *d if (_csync_vio_local_stat_mb(fullPath.data(), file_stat.get()) < 0) { // Will get excluded by _csync_detect_update. - file_stat->type = CSYNC_FTW_TYPE_SKIP; + file_stat->type = ItemTypeSkip; } return file_stat; diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 4657e0488..eb0ce8d3e 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -310,9 +310,9 @@ static std::unique_ptr<csync_file_stat_t> propertyMapToFileStat(const QMap<QStri QString value = it.value(); if (property == "resourcetype") { if (value.contains("collection")) { - file_stat->type = CSYNC_FTW_TYPE_DIR; + file_stat->type = ItemTypeDirectory; } else { - file_stat->type = CSYNC_FTW_TYPE_FILE; + file_stat->type = ItemTypeFile; } } else if (property == "getlastmodified") { file_stat->modtime = oc_httpdate_parse(value.toUtf8()); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 6dc571c72..5e387921c 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -278,7 +278,7 @@ void SyncEngine::deleteStaleDownloadInfos(const SyncFileItemVector &syncItems) QSet<QString> download_file_paths; foreach (const SyncFileItemPtr &it, syncItems) { if (it->_direction == SyncFileItem::Down - && it->_type == SyncFileItem::File) { + && it->_type == ItemTypeFile) { download_file_paths.insert(it->_file); } } @@ -299,7 +299,7 @@ void SyncEngine::deleteStaleUploadInfos(const SyncFileItemVector &syncItems) QSet<QString> upload_file_paths; foreach (const SyncFileItemPtr &it, syncItems) { if (it->_direction == SyncFileItem::Up - && it->_type == SyncFileItem::File) { + && it->_type == ItemTypeFile) { upload_file_paths.insert(it->_file); } } @@ -529,7 +529,7 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other, item->_errorString = tr("Filename encoding is not valid"); } - bool isDirectory = file->type == CSYNC_FTW_TYPE_DIR; + bool isDirectory = file->type == ItemTypeDirectory; if (!file->etag.isEmpty()) { item->_etag = file->etag; @@ -540,19 +540,7 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other, item->_inode = file->inode; } - switch (file->type) { - case CSYNC_FTW_TYPE_DIR: - item->_type = SyncFileItem::Directory; - break; - case CSYNC_FTW_TYPE_FILE: - item->_type = SyncFileItem::File; - break; - case CSYNC_FTW_TYPE_SLINK: - item->_type = SyncFileItem::SoftLink; - break; - default: - item->_type = SyncFileItem::UnknownType; - } + item->_type = file->type; SyncFileItem::Direction dir = SyncFileItem::None; diff --git a/src/libsync/syncfileitem.cpp b/src/libsync/syncfileitem.cpp index bfea07163..832feefde 100644 --- a/src/libsync/syncfileitem.cpp +++ b/src/libsync/syncfileitem.cpp @@ -58,7 +58,7 @@ SyncFileItemPtr SyncFileItem::fromSyncJournalFileRecord(const SyncJournalFileRec item->_file = rec._path; item->_inode = rec._inode; item->_modtime = rec._modtime; - item->_type = static_cast<SyncFileItem::Type>(rec._type); + item->_type = rec._type; item->_etag = rec._etag; item->_fileId = rec._fileId; item->_size = rec._fileSize; diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index dd364ae43..aac2bd48d 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -42,13 +42,6 @@ public: Down }; - enum Type { - UnknownType = 0, - File = CSYNC_FTW_TYPE_FILE, - Directory = CSYNC_FTW_TYPE_DIR, - SoftLink = CSYNC_FTW_TYPE_SLINK - }; - enum Status { // stored in 4 bits NoStatus, @@ -101,7 +94,7 @@ public: SyncFileItem() - : _type(UnknownType) + : _type(ItemTypeSkip) , _direction(None) , _serverHasIgnoredFiles(false) , _hasBlacklistEntry(false) @@ -173,7 +166,7 @@ public: bool isDirectory() const { - return _type == SyncFileItem::Directory; + return _type == ItemTypeDirectory; } /** @@ -195,7 +188,7 @@ public: // Variables useful for everybody QString _file; QString _renameTarget; - Type _type BITFIELD(3); + ItemType _type BITFIELD(3); Direction _direction BITFIELD(3); bool _serverHasIgnoredFiles BITFIELD(1); diff --git a/test/csync/csync_tests/check_csync_exclude.cpp b/test/csync/csync_tests/check_csync_exclude.cpp index b01f4cdc8..7c64ce5de 100644 --- a/test/csync/csync_tests/check_csync_exclude.cpp +++ b/test/csync/csync_tests/check_csync_exclude.cpp @@ -90,22 +90,22 @@ static int teardown(void **state) { static int check_file_full(const char *path) { - return excludedFiles->fullPatternMatch(path, CSYNC_FTW_TYPE_FILE); + return excludedFiles->fullPatternMatch(path, ItemTypeFile); } static int check_dir_full(const char *path) { - return excludedFiles->fullPatternMatch(path, CSYNC_FTW_TYPE_DIR); + return excludedFiles->fullPatternMatch(path, ItemTypeDirectory); } static int check_file_traversal(const char *path) { - return excludedFiles->traversalPatternMatch(path, CSYNC_FTW_TYPE_FILE); + return excludedFiles->traversalPatternMatch(path, ItemTypeFile); } static int check_dir_traversal(const char *path) { - return excludedFiles->traversalPatternMatch(path, CSYNC_FTW_TYPE_DIR); + return excludedFiles->traversalPatternMatch(path, ItemTypeDirectory); } static void check_csync_exclude_add(void **) diff --git a/test/csync/csync_tests/check_csync_update.cpp b/test/csync/csync_tests/check_csync_update.cpp index db6819907..01681b7de 100644 --- a/test/csync/csync_tests/check_csync_update.cpp +++ b/test/csync/csync_tests/check_csync_update.cpp @@ -184,7 +184,7 @@ static std::unique_ptr<csync_file_stat_t> create_fstat(const char *name, fs->path = "file.txt"; } - fs->type = CSYNC_FTW_TYPE_FILE; + fs->type = ItemTypeFile; if (inode == 0) { fs->inode = 619070; diff --git a/test/csync/vio_tests/check_vio_ext.cpp b/test/csync/vio_tests/check_vio_ext.cpp index f86ce9591..f0e772956 100644 --- a/test/csync/vio_tests/check_vio_ext.cpp +++ b/test/csync/vio_tests/check_vio_ext.cpp @@ -218,7 +218,7 @@ static void traverse_dir(void **state, const char *dir, int *cnt) continue; } - is_dir = (dirent->type == CSYNC_FTW_TYPE_DIR) ? 1:0; + is_dir = (dirent->type == ItemTypeDirectory) ? 1:0; assert_int_not_equal( asprintf( &subdir, "%s/%s", dir, dirent->path.constData() ), -1 ); diff --git a/test/testsyncjournaldb.cpp b/test/testsyncjournaldb.cpp index cb86a1655..389dcec5d 100644 --- a/test/testsyncjournaldb.cpp +++ b/test/testsyncjournaldb.cpp @@ -54,7 +54,7 @@ private slots: // signed int being cast to uint64 either (like uint64::max would be) record._inode = std::numeric_limits<quint32>::max() + 12ull; record._modtime = dropMsecs(QDateTime::currentDateTime()); - record._type = 5; + record._type = ItemTypeDirectory; record._etag = "789789"; record._fileId = "abcd"; record._remotePerm = RemotePermissions("RW"); @@ -76,7 +76,7 @@ private slots: record._modtime = dropMsecs(QDateTime::currentDateTime().addDays(1)); // try a value that only fits uint64, not int64 record._inode = std::numeric_limits<quint64>::max() - std::numeric_limits<quint32>::max() - 1; - record._type = 7; + record._type = ItemTypeFile; record._etag = "789FFF"; record._fileId = "efg"; record._remotePerm = RemotePermissions("NV"); |