Correcting action-item.proto and adding seg_no processing in action log API
diff --git a/src/action-item.proto b/src/action-item.proto
index c7eca9c..1008ba6 100644
--- a/src/action-item.proto
+++ b/src/action-item.proto
@@ -2,10 +2,10 @@
{
enum ActionType
{
- UPDATE = 0;
- DELETE = 1;
+ UPDATE = 1;
+ DELETE = 2;
}
- required ActionType action = 0;
+ required ActionType action = 14;
required string filename = 1;
required uint64 version = 2;
@@ -15,9 +15,9 @@
optional uint32 mtime = 6;
optional uint32 mode = 7;
- optional uint32 atime = 8;
- optional uint32 ctime = 9;
+ // optional uint32 atime = 8;
+ // optional uint32 ctime = 9;
- // optional bytes parent_device_name = 12;
- // optional uint64 parent_seq_no = 13;
+ optional bytes parent_device_name = 12;
+ optional uint64 parent_seq_no = 13;
}
diff --git a/src/action-log.cc b/src/action-log.cc
index cc0d945..e15bbc6 100644
--- a/src/action-log.cc
+++ b/src/action-log.cc
@@ -85,7 +85,8 @@
ActionLog::AddActionUpdate (const std::string &filename,
const Hash &hash,
time_t wtime,
- int mode)
+ int mode,
+ int seg_num)
{
sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
@@ -102,7 +103,7 @@
sqlite3_stmt *stmt;
int res = sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
"(device_id, seq_no, action, filename, version, action_timestamp, "
- "file_hash, file_atime, file_mtime, file_ctime, file_chmod, "
+ "file_hash, file_atime, file_mtime, file_ctime, file_chmod, file_seg_num, "
"parent_device_id, parent_seq_no, "
"action_name, action_content_object) "
"VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
@@ -140,16 +141,17 @@
sqlite3_bind_int64 (stmt, 9, wtime);
// sqlite3_bind_int64 (stmt, 10, ctime); // NULL
sqlite3_bind_int (stmt, 11, mode);
+ sqlite3_bind_int (stmt, 12, seg_num);
if (parent_device_id > 0 && parent_seq_no > 0)
{
- sqlite3_bind_int64 (stmt, 12, parent_device_id);
- sqlite3_bind_int64 (stmt, 13, parent_seq_no);
+ sqlite3_bind_int64 (stmt, 13, parent_device_id);
+ sqlite3_bind_int64 (stmt, 14, parent_seq_no);
}
else
{
- sqlite3_bind_null (stmt, 12);
sqlite3_bind_null (stmt, 13);
+ sqlite3_bind_null (stmt, 14);
}
// missing part: creating ContentObject for the action !!!
@@ -164,6 +166,7 @@
item.set_mtime (wtime);
// item.set_ctime (ctime);
item.set_mode (mode);
+ item.set_seg_num (seg_num);
if (parent_device_id > 0 && parent_seq_no > 0)
{
@@ -286,9 +289,9 @@
{
ActionLog *the = reinterpret_cast<ActionLog*> (sqlite3_user_data (context));
- if (argc != 10)
+ if (argc != 11)
{
- sqlite3_result_error (context, "``apply_action'' expects 8 arguments", -1);
+ sqlite3_result_error (context, "``apply_action'' expects 11 arguments", -1);
return;
}
@@ -311,6 +314,7 @@
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]);
+ int seg_num = sqlite3_value_int (argv[10]);
cout << "Update " << filename << " " << atime << " " << mtime << " " << ctime << " " << hash << endl;
@@ -323,6 +327,7 @@
"file_mtime=datetime(?, 'unixepoch'),"
"file_ctime=datetime(?, 'unixepoch'),"
"file_chmod=? "
+ "file_seg_num=? "
"WHERE type=0 AND filename=?", -1, &stmt, 0);
sqlite3_bind_int64 (stmt, 1, device_id);
@@ -332,7 +337,8 @@
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_bind_int (stmt, 8, seg_num);
+ sqlite3_bind_text (stmt, 9, filename.c_str (), -1, SQLITE_TRANSIENT);
sqlite3_step (stmt);
diff --git a/src/action-log.h b/src/action-log.h
index 7d778d8..ed7a76a 100644
--- a/src/action-log.h
+++ b/src/action-log.h
@@ -39,7 +39,8 @@
AddActionUpdate (const std::string &filename,
const Hash &hash,
time_t wtime,
- int mode);
+ int mode,
+ int seg_num);
void
AddActionMove (const std::string &oldFile, const std::string &newFile);
diff --git a/src/db-helper.cc b/src/db-helper.cc
index 4313dfd..82feb89 100644
--- a/src/db-helper.cc
+++ b/src/db-helper.cc
@@ -144,7 +144,7 @@
NEW.device_id, NEW.seq_no, \
NEW.action,NEW.filename,NEW.file_hash, \
strftime('%s', NEW.file_atime),strftime('%s', NEW.file_mtime),strftime('%s', NEW.file_ctime), \
- NEW.file_chmod); /* function that applies action and adds record the FileState */ \n \
+ NEW.file_chmod, NEW.file_seg_num); /* function that applies action and adds record the FileState */ \n \
END; \n\
\n\
CREATE TABLE FileState ( \n\
@@ -157,6 +157,7 @@
file_mtime TIMESTAMP, \n\
file_ctime TIMESTAMP, \n\
file_chmod INTEGER, \n\
+ file_seg_num INTEGER, \n\
\n\
PRIMARY KEY (type, filename) \n\
); \n\