typedef struct csync_file_stat_s csync_file_stat_t;
struct OCSYNC_EXPORT csync_file_stat_s {
- uint64_t phash;
time_t modtime;
int64_t size;
uint64_t inode;
enum csync_instructions_e instruction; /* u32 */
csync_file_stat_s()
- : phash(0)
- , modtime(0)
+ : modtime(0)
, size(0)
, inode(0)
, type(CSYNC_FTW_TYPE_SKIP)
}
#define METADATA_QUERY \
- "phash, path, inode, modtime, type, md5, fileid, remotePerm, " \
+ "path, inode, modtime, type, md5, fileid, remotePerm, " \
"filesize, ignoredChildrenRemote, " \
"contentchecksumtype.name || ':' || contentChecksum " \
"FROM metadata " \
}
// Callers should all use METADATA_QUERY for their column list.
- assert(sqlite3_column_count(stmt) == 11);
+ assert(sqlite3_column_count(stmt) == 10);
SQLITE_BUSY_HANDLED( sqlite3_step(stmt) );
if( rc == SQLITE_ROW ) {
st.reset(new csync_file_stat_t);
- /* The query suceeded so use the phash we pass to the function. */
- st->phash = sqlite3_column_int64(stmt, 0);
- st->path = (char*)sqlite3_column_text(stmt, 1);
- st->inode = sqlite3_column_int64(stmt, 2);
- st->modtime = strtoul((char*)sqlite3_column_text(stmt, 3), NULL, 10);
- st->type = static_cast<enum csync_ftw_type_e>(sqlite3_column_int(stmt, 4));
- st->etag = (char*)sqlite3_column_text(stmt, 5);
- st->file_id = (char*)sqlite3_column_text(stmt, 6);
- st->remotePerm = (char*)sqlite3_column_text(stmt, 7);
- st->size = sqlite3_column_int64(stmt, 8);
- st->has_ignored_files = sqlite3_column_int(stmt, 9);
- st->checksumHeader = (char *)sqlite3_column_text(stmt, 10);
+ st->path = (char*)sqlite3_column_text(stmt, 0);
+ st->inode = sqlite3_column_int64(stmt, 1);
+ st->modtime = strtoul((char*)sqlite3_column_text(stmt, 2), NULL, 10);
+ st->type = static_cast<enum csync_ftw_type_e>(sqlite3_column_int(stmt, 3));
+ st->etag = (char*)sqlite3_column_text(stmt, 4);
+ st->file_id = (char*)sqlite3_column_text(stmt, 5);
+ st->remotePerm = (char*)sqlite3_column_text(stmt, 6);
+ st->size = sqlite3_column_int64(stmt, 7);
+ st->has_ignored_files = sqlite3_column_int(stmt, 8);
+ st->checksumHeader = (char *)sqlite3_column_text(stmt, 9);
} else {
if( rc != SQLITE_DONE ) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Query results in %d", rc);
}
/* caller must free the memory */
-std::unique_ptr<csync_file_stat_t> csync_statedb_get_stat_by_hash(CSYNC *ctx,
- uint64_t phash)
+std::unique_ptr<csync_file_stat_t> csync_statedb_get_stat_by_path(CSYNC *ctx, const QByteArray &path)
{
std::unique_ptr<csync_file_stat_t> st;
int rc;
return NULL;
}
+ uint64_t phash = c_jhash64((const uint8_t*)path.constData(), path.size(), 0);
sqlite3_bind_int64(ctx->statedb.by_hash_stmt, 1, (long long signed int)phash);
rc = _csync_file_stat_from_metadata_table(st, ctx->statedb.by_hash_stmt);
OCSYNC_EXPORT int csync_statedb_close(CSYNC *ctx);
-OCSYNC_EXPORT std::unique_ptr<csync_file_stat_t> csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash);
+OCSYNC_EXPORT std::unique_ptr<csync_file_stat_t> csync_statedb_get_stat_by_path(CSYNC *ctx, const QByteArray &path);
OCSYNC_EXPORT std::unique_ptr<csync_file_stat_t> csync_statedb_get_stat_by_inode(CSYNC *ctx, uint64_t inode);
#include <math.h>
#include "c_lib.h"
-#include "c_jhash.h"
#include "csync_private.h"
#include "csync_exclude.h"
* does not change on rename.
*/
if (csync_get_statedb_exists(ctx)) {
- tmp = csync_statedb_get_stat_by_hash(ctx, fs->phash);
+ tmp = csync_statedb_get_stat_by_path(ctx, fs->path);
if(_last_db_return_error(ctx)) {
ctx->status_code = CSYNC_STATUS_UNSUCCESSFUL;
return -1;
}
- if(tmp && tmp->phash == fs->phash ) { /* there is an entry in the database */
+ if(tmp && tmp->path == fs->path ) { /* there is an entry in the database */
/* we have an update! */
CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, "Database entry found, compare: %" PRId64 " <-> %" PRId64
", etag: %s <-> %s, inode: %" PRId64 " <-> %" PRId64
// "len + 1" to include the slash in-between.
dirent->path = dirent->path.mid(strlen(ctx->local.uri) + 1);
}
- // We calculate the phash using the relative path.
- dirent->phash = c_jhash64((const uint8_t*)dirent->path.constData(), dirent->path.size(), 0);
previous_fs = ctx->current_fs;
bool recurse = dirent->type == CSYNC_FTW_TYPE_DIR;
for (i = 0; i < 100; i++) {
st.reset(new csync_file_stat_t);
st->path = QString("file_%1").arg(i).toUtf8();
- st->phash = i;
csync->local.files[st->path] = std::move(st);
}
for (i = 0; i < 100; i++) {
st.reset(new csync_file_stat_t);
st->path = QString("file_%1").arg(i).toUtf8();
- st->phash = i;
csync->local.files[st->path] = std::move(st);
assert_int_equal(rc, 0);
}
-static void check_csync_statedb_get_stat_by_hash_not_found(void **state)
+static void check_csync_statedb_get_stat_by_path_not_found(void **state)
{
CSYNC *csync = (CSYNC*)*state;
std::unique_ptr<csync_file_stat_t> tmp;
- tmp = csync_statedb_get_stat_by_hash(csync, (uint64_t) 666);
+ tmp = csync_statedb_get_stat_by_path(csync, "666");
assert_null(tmp.get());
}
cmocka_unit_test_setup_teardown(check_csync_statedb_drop_tables, setup, teardown),
cmocka_unit_test_setup_teardown(check_csync_statedb_insert_metadata, setup, teardown),
cmocka_unit_test_setup_teardown(check_csync_statedb_write, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_hash_not_found, setup_db, teardown),
+ cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_path_not_found, setup_db, teardown),
cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_inode_not_found, setup_db, teardown),
};
}
void testFullResult() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash( _ctx, 2081025720555645157 );
+ std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_path( _ctx, "test2/zu/zuzu" );
QVERIFY(st.get());
- QCOMPARE( QString::number(st->phash), QString::number(2081025720555645157) );
QCOMPARE( QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu") );
QCOMPARE( QString::number(st->inode), QString::number(1709554));
QCOMPARE( QString::number(st->modtime), QString::number(1384415006));
}
void testByHash() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash(_ctx, -7147279406142960289);
+ std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_path(_ctx, "documents/c1");
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1"));
- st = csync_statedb_get_stat_by_hash(_ctx, 5426481156826978940);
+ st = csync_statedb_get_stat_by_path(_ctx, "documents/c1/c2");
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1/c2"));
}