Now FileState is linked to ActionLog
diff --git a/src/action-log.cc b/src/action-log.cc
index 3b9f757..9c8f50d 100644
--- a/src/action-log.cc
+++ b/src/action-log.cc
@@ -245,7 +245,7 @@
{
ActionLog *the = reinterpret_cast<ActionLog*> (sqlite3_user_data (context));
- if (argc != 8)
+ if (argc != 10)
{
sqlite3_result_error (context, "``apply_action'' expects 8 arguments", -1);
return;
@@ -258,36 +258,45 @@
// cout << "filename: " << sqlite3_value_text (argv[2]) << endl;
string device_name = reinterpret_cast<const char*> (sqlite3_value_text (argv[0]));
- int action = sqlite3_value_int (argv[1]);
- string filename = reinterpret_cast<const char*> (sqlite3_value_text (argv[2]));
+ sqlite3_int64 device_id = sqlite3_value_int64 (argv[1]);
+ sqlite3_int64 seq_no = sqlite3_value_int64 (argv[2]);
+ int action = sqlite3_value_int (argv[3]);
+ string filename = reinterpret_cast<const char*> (sqlite3_value_text (argv[4]));
if (action == 0) // update
{
- Hash hash (sqlite3_value_blob (argv[3]), sqlite3_value_bytes (argv[3]));
- time_t atime = static_cast<time_t> (sqlite3_value_int64 (argv[4]));
- time_t mtime = static_cast<time_t> (sqlite3_value_int64 (argv[5]));
- time_t ctime = static_cast<time_t> (sqlite3_value_int64 (argv[6]));
- int mode = sqlite3_value_int (argv[7]);
+ Hash hash (sqlite3_value_blob (argv[5]), sqlite3_value_bytes (argv[5]));
+ time_t atime = static_cast<time_t> (sqlite3_value_int64 (argv[6]));
+ time_t mtime = static_cast<time_t> (sqlite3_value_int64 (argv[7]));
+ time_t ctime = static_cast<time_t> (sqlite3_value_int64 (argv[8]));
+ int mode = sqlite3_value_int (argv[9]);
- cout << "Update " << filename << " " << atime << " " << mtime << " " << ctime << endl;
+ cout << "Update " << filename << " " << atime << " " << mtime << " " << ctime << " " << hash << endl;
sqlite3_stmt *stmt;
sqlite3_prepare_v2 (the->m_db, "UPDATE FileState "
- "SET file_hash=?,"
+ "SET "
+ "device_id=?, seq_no=?, "
+ "file_hash=?,"
"file_atime=datetime(?, 'unixepoch'),"
"file_mtime=datetime(?, 'unixepoch'),"
"file_ctime=datetime(?, 'unixepoch'),"
"file_chmod=? "
"WHERE type=0 AND filename=?", -1, &stmt, 0);
- sqlite3_bind_blob (stmt, 1, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
- sqlite3_bind_int64 (stmt, 2, atime);
- sqlite3_bind_int64 (stmt, 3, mtime);
- sqlite3_bind_int64 (stmt, 4, ctime);
- sqlite3_bind_int (stmt, 5, mode);
- sqlite3_bind_text (stmt, 6, filename.c_str (), -1, SQLITE_TRANSIENT);
+ sqlite3_bind_int64 (stmt, 1, device_id);
+ sqlite3_bind_int64 (stmt, 2, seq_no);
+ sqlite3_bind_blob (stmt, 3, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
+ sqlite3_bind_int64 (stmt, 4, atime);
+ sqlite3_bind_int64 (stmt, 5, mtime);
+ sqlite3_bind_int64 (stmt, 6, ctime);
+ sqlite3_bind_int (stmt, 7, mode);
+ sqlite3_bind_text (stmt, 8, filename.c_str (), -1, SQLITE_TRANSIENT);
sqlite3_step (stmt);
+
+ // cout << sqlite3_errmsg (the->m_db) << endl;
+
sqlite3_finalize (stmt);
int affected_rows = sqlite3_changes (the->m_db);
@@ -295,18 +304,21 @@
{
sqlite3_stmt *stmt;
sqlite3_prepare_v2 (the->m_db, "INSERT INTO FileState "
- "(type,filename,file_hash,file_atime,file_mtime,file_ctime,file_chmod) "
- "VALUES (0, ?, ?, "
+ "(type,filename,device_id,seq_no,file_hash,file_atime,file_mtime,file_ctime,file_chmod) "
+ "VALUES (0, ?, ?, ?, ?, "
"datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)", -1, &stmt, 0);
sqlite3_bind_text (stmt, 1, filename.c_str (), -1, SQLITE_TRANSIENT);
- sqlite3_bind_blob (stmt, 2, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
- sqlite3_bind_int64 (stmt, 3, atime);
- sqlite3_bind_int64 (stmt, 4, mtime);
- sqlite3_bind_int64 (stmt, 5, ctime);
- sqlite3_bind_int (stmt, 6, mode);
+ sqlite3_bind_int64 (stmt, 2, device_id);
+ sqlite3_bind_int64 (stmt, 3, seq_no);
+ sqlite3_bind_blob (stmt, 4, hash.GetHash (), hash.GetHashBytes (), SQLITE_TRANSIENT);
+ sqlite3_bind_int64 (stmt, 5, atime);
+ sqlite3_bind_int64 (stmt, 6, mtime);
+ sqlite3_bind_int64 (stmt, 7, ctime);
+ sqlite3_bind_int (stmt, 8, mode);
sqlite3_step (stmt);
+ // cout << sqlite3_errmsg (the->m_db) << endl;
sqlite3_finalize (stmt);
}
}