blob: 84c277983315729bf760d088402b786dd8c4333b [file] [log] [blame]
Alexander Afanasyeva199f972013-01-02 19:37:26 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012-2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
22#include "action-log.h"
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080023#include "logging.h"
Alexander Afanasyeva199f972013-01-02 19:37:26 -080024
Alexander Afanasyev0995f322013-01-22 13:16:46 -080025#include <boost/make_shared.hpp>
26
Alexander Afanasyeva199f972013-01-02 19:37:26 -080027using namespace boost;
28using namespace std;
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080029using namespace Ccnx;
Alexander Afanasyeva199f972013-01-02 19:37:26 -080030
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080031INIT_LOGGER ("ActionLog");
32
33const std::string INIT_DATABASE = "\
34CREATE TABLE ActionLog ( \n\
Alexander Afanasyev0995f322013-01-22 13:16:46 -080035 device_name BLOB NOT NULL, \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080036 seq_no INTEGER NOT NULL, \n\
37 \n\
38 action CHAR(1) NOT NULL, /* 0 for \"update\", 1 for \"delete\". */ \n\
39 filename TEXT NOT NULL, \n\
40 \n\
41 version INTEGER NOT NULL, \n\
42 action_timestamp TIMESTAMP NOT NULL, \n\
43 \n\
44 file_hash BLOB, /* NULL if action is \"delete\" */ \n\
45 file_atime TIMESTAMP, \n\
46 file_mtime TIMESTAMP, \n\
47 file_ctime TIMESTAMP, \n\
48 file_chmod INTEGER, \n\
49 file_seg_num INTEGER, /* NULL if action is \"delete\" */ \n\
50 \n\
Alexander Afanasyev0995f322013-01-22 13:16:46 -080051 parent_device_name BLOB, \n\
52 parent_seq_no INTEGER, \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080053 \n\
54 action_name TEXT, \n\
55 action_content_object BLOB, \n\
56 \n\
Alexander Afanasyev785b0a02013-01-30 10:17:47 -080057 PRIMARY KEY (device_name, seq_no) \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080058); \n\
59 \n\
Alexander Afanasyev0995f322013-01-22 13:16:46 -080060CREATE INDEX ActionLog_filename_version ON ActionLog (filename,version); \n\
61CREATE INDEX ActionLog_parent ON ActionLog (parent_device_name, parent_seq_no); \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080062CREATE INDEX ActionLog_action_name ON ActionLog (action_name); \n\
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080063CREATE INDEX ActionLog_filename_version_hash ON ActionLog (filename,version,file_hash); \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080064 \n\
65CREATE TRIGGER ActionLogInsert_trigger \n\
66 AFTER INSERT ON ActionLog \n\
67 FOR EACH ROW \n\
Alexander Afanasyev0995f322013-01-22 13:16:46 -080068 WHEN (SELECT device_name \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080069 FROM ActionLog \n\
70 WHERE filename=NEW.filename AND \n\
71 version > NEW.version) IS NULL AND \n\
Alexander Afanasyev0995f322013-01-22 13:16:46 -080072 (SELECT device_name \n\
73 FROM ActionLog \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080074 WHERE filename=NEW.filename AND \n\
75 version = NEW.version AND \n\
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080076 device_name > NEW.device_name) IS NULL \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080077 BEGIN \n\
Alexander Afanasyev0995f322013-01-22 13:16:46 -080078 SELECT apply_action (NEW.device_name, NEW.seq_no, \
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080079 NEW.action,NEW.filename,NEW.file_hash, \
80 strftime('%s', NEW.file_atime),strftime('%s', NEW.file_mtime),strftime('%s', NEW.file_ctime), \
81 NEW.file_chmod, NEW.file_seg_num); /* function that applies action and adds record the FileState */ \n \
82 END; \n\
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080083";
84
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -080085// static void xTrace (void*, const char* q)
86// {
87// _LOG_TRACE ("SQLITE: " << q);
88// }
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080089
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080090ActionLog::ActionLog (Ccnx::CcnxWrapperPtr ccnx, const boost::filesystem::path &path,
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080091 SyncLogPtr syncLog,
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080092 const std::string &sharedFolder, const std::string &appName,
Alexander Afanasyevf9978f82013-01-23 16:30:31 -080093 OnFileAddedOrChangedCallback onFileAddedOrChanged, OnFileRemovedCallback onFileRemoved)
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080094 : DbHelper (path / ".chronoshare", "action-log.db")
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080095 , m_syncLog (syncLog)
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080096 , m_ccnx (ccnx)
97 , m_sharedFolderName (sharedFolder)
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080098 , m_appName (appName)
Alexander Afanasyevf9978f82013-01-23 16:30:31 -080099 , m_onFileAddedOrChanged (onFileAddedOrChanged)
100 , m_onFileRemoved (onFileRemoved)
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800101{
Alexander Afanasyev785b0a02013-01-30 10:17:47 -0800102 sqlite3_exec (m_db, "PRAGMA foreign_keys = OFF", NULL, NULL, NULL);
103 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
104
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -0800105 sqlite3_exec (m_db, INIT_DATABASE.c_str (), NULL, NULL, NULL);
106 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
107
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800108 int res = sqlite3_create_function (m_db, "apply_action", -1, SQLITE_ANY, reinterpret_cast<void*> (this),
109 ActionLog::apply_action_xFun,
110 0, 0);
111 if (res != SQLITE_OK)
112 {
113 BOOST_THROW_EXCEPTION (Error::Db ()
114 << errmsg_info_str ("Cannot create function ``apply_action''"));
115 }
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800116
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800117 m_fileState = make_shared<FileState> (path);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800118}
119
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800120tuple<sqlite3_int64 /*version*/, Ccnx::CcnxCharbufPtr /*device name*/, sqlite3_int64 /*seq_no*/>
121ActionLog::GetLatestActionForFile (const std::string &filename)
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800122{
123 // check if something already exists
124 sqlite3_stmt *stmt;
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800125 int res = sqlite3_prepare_v2 (m_db, "SELECT version,device_name,seq_no,action "
126 "FROM ActionLog "
127 "WHERE filename=? ORDER BY version DESC LIMIT 1", -1, &stmt, 0);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800128
129 if (res != SQLITE_OK)
130 {
131 BOOST_THROW_EXCEPTION (Error::Db ()
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800132 << errmsg_info_str ("Some error with GetExistingRecord"));
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800133 }
134
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800135 sqlite3_int64 version = -1;
136 CcnxCharbufPtr parent_device_name;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800137 sqlite3_int64 parent_seq_no = -1;
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800138
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800139 sqlite3_bind_text (stmt, 1, filename.c_str (), filename.size (), SQLITE_STATIC);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800140 if (sqlite3_step (stmt) == SQLITE_ROW)
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800141 {
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800142 version = sqlite3_column_int64 (stmt, 0);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800143
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800144 if (sqlite3_column_int (stmt, 3) == 0) // prevent "linking" if the file was previously deleted
145 {
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800146 parent_device_name = make_shared<CcnxCharbuf> (sqlite3_column_blob (stmt, 1), sqlite3_column_bytes (stmt, 1));
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800147 parent_seq_no = sqlite3_column_int64 (stmt, 2);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800148 }
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800149 }
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800150
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800151 sqlite3_finalize (stmt);
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800152 return make_tuple (version, parent_device_name, parent_seq_no);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800153}
154
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800155// local add action. remote action is extracted from content object
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800156ActionItemPtr
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800157ActionLog::AddLocalActionUpdate (const std::string &filename,
158 const Hash &hash,
159 time_t wtime,
160 int mode,
161 int seg_num)
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800162{
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800163 sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800164
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800165 CcnxCharbufPtr device_name = m_syncLog->GetLocalName ().toCcnxCharbuf ();
166 sqlite3_int64 seq_no = m_syncLog->GetNextLocalSeqNo ();
167 sqlite3_int64 version;
168 CcnxCharbufPtr parent_device_name;
169 sqlite3_int64 parent_seq_no = -1;
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800170
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800171 sqlite3_int64 action_time = time (0);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800172
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800173 tie (version, parent_device_name, parent_seq_no) = GetLatestActionForFile (filename);
174 version ++;
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800175
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800176 sqlite3_stmt *stmt;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800177 int res = sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800178 "(device_name, seq_no, action, filename, version, action_timestamp, "
Alexander Afanasyev334aac82013-01-18 14:06:39 -0800179 "file_hash, file_atime, file_mtime, file_ctime, file_chmod, file_seg_num, "
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800180 "parent_device_name, parent_seq_no, "
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800181 "action_name, action_content_object) "
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800182 "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800183 " ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,?, "
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800184 " ?, ?, "
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800185 " ?, ?);", -1, &stmt, 0);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800186
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800187 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
188
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800189 if (res != SQLITE_OK)
190 {
191 BOOST_THROW_EXCEPTION (Error::Db ()
192 << errmsg_info_str (sqlite3_errmsg (m_db))
193 );
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800194 }
195
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800196 sqlite3_bind_blob (stmt, 1, device_name->buf (), device_name->length (), SQLITE_STATIC);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800197 sqlite3_bind_int64 (stmt, 2, seq_no);
198 sqlite3_bind_int (stmt, 3, 0);
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800199 sqlite3_bind_text (stmt, 4, filename.c_str (), filename.size (), SQLITE_STATIC);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800200 sqlite3_bind_int64 (stmt, 5, version);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800201 sqlite3_bind_int64 (stmt, 6, action_time);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800202
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800203 sqlite3_bind_blob (stmt, 7, hash.GetHash (), hash.GetHashBytes (), SQLITE_STATIC);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800204
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800205 // sqlite3_bind_int64 (stmt, 8, atime); // NULL
206 sqlite3_bind_int64 (stmt, 9, wtime);
207 // sqlite3_bind_int64 (stmt, 10, ctime); // NULL
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800208 sqlite3_bind_int (stmt, 11, mode);
Alexander Afanasyev334aac82013-01-18 14:06:39 -0800209 sqlite3_bind_int (stmt, 12, seg_num);
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800210
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800211 if (parent_device_name && parent_seq_no > 0)
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800212 {
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800213 sqlite3_bind_blob (stmt, 13, parent_device_name->buf (), parent_device_name->length (), SQLITE_STATIC);
Alexander Afanasyev334aac82013-01-18 14:06:39 -0800214 sqlite3_bind_int64 (stmt, 14, parent_seq_no);
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800215 }
Alexander Afanasyev433ecda2013-01-02 22:13:45 -0800216
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800217 ActionItemPtr item = make_shared<ActionItem> ();
218 item->set_action (ActionItem::UPDATE);
219 item->set_filename (filename);
220 item->set_version (version);
221 item->set_timestamp (action_time);
222 item->set_file_hash (hash.GetHash (), hash.GetHashBytes ());
223 // item->set_atime (atime);
224 item->set_mtime (wtime);
225 // item->set_ctime (ctime);
226 item->set_mode (mode);
227 item->set_seg_num (seg_num);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800228
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800229 if (parent_device_name && parent_seq_no > 0)
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800230 {
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800231 // cout << Name (*parent_device_name) << endl;
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800232
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800233 item->set_parent_device_name (parent_device_name->buf (), parent_device_name->length ());
234 item->set_parent_seq_no (parent_seq_no);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800235 }
236
237 // assign name to the action, serialize action, and create content object
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800238
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -0800239
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800240 string item_msg;
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800241 item->SerializeToString (&item_msg);
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -0800242
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800243 // action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq>
244 Name actionName = Name ("/")(m_syncLog->GetLocalName ())(m_appName)("action")(m_sharedFolderName)(seq_no);
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800245 _LOG_DEBUG ("ActionName: " << actionName);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800246
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800247 Bytes actionData = m_ccnx->createContentObject (actionName, item_msg.c_str (), item_msg.size ());
248 CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf ();
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800249
Alexander Afanasyevfc720362013-01-24 21:49:48 -0800250 // _LOG_DEBUG (" >>>>>>> " << Name (namePtr->buf () << " " << namePtr->length ());
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800251
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800252 sqlite3_bind_blob (stmt, 15, namePtr->buf (), namePtr->length (), SQLITE_STATIC);
253 sqlite3_bind_blob (stmt, 16, head (actionData), actionData.size (), SQLITE_STATIC);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800254
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800255 sqlite3_step (stmt);
256
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800257 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800258
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800259 sqlite3_finalize (stmt);
260
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800261 sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800262
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800263 // set complete for local file
264 m_fileState->SetFileComplete(filename);
265
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800266 return item;
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800267}
268
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800269// void
270// ActionLog::AddActionMove (const std::string &oldFile, const std::string &newFile)
271// {
272// // not supported yet
273// BOOST_THROW_EXCEPTION (Error::Db ()
274// << errmsg_info_str ("Move operation is not yet supported"));
275// }
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800276
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800277ActionItemPtr
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800278ActionLog::AddLocalActionDelete (const std::string &filename)
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800279{
Alexander Afanasyev4a8781c2013-01-29 17:59:44 -0800280 _LOG_DEBUG ("Adding local action DELETE");
281
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800282 sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800283
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800284 CcnxCharbufPtr device_name = m_syncLog->GetLocalName ().toCcnxCharbuf ();
285 sqlite3_int64 version;
286 CcnxCharbufPtr parent_device_name;
287 sqlite3_int64 parent_seq_no = -1;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800288
289 sqlite3_int64 action_time = time (0);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800290
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800291 tie (version, parent_device_name, parent_seq_no) = GetLatestActionForFile (filename);
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800292 if (!parent_device_name) // no records exist or file was already deleted
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800293 {
Alexander Afanasyev4a8781c2013-01-29 17:59:44 -0800294 _LOG_DEBUG ("Nothing to delete... [" << filename << "]");
295
296 // just in case, remove data from FileState
297 sqlite3_stmt *stmt;
298 sqlite3_prepare_v2 (m_db, "DELETE FROM FileState WHERE filename = ? ", -1, &stmt, 0);
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800299 sqlite3_bind_text (stmt, 1, filename.c_str (), filename.size (), SQLITE_STATIC); // file
Alexander Afanasyev4a8781c2013-01-29 17:59:44 -0800300
301 sqlite3_step (stmt);
302
303 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
304
305 sqlite3_finalize (stmt);
306
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800307 sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800308 return ActionItemPtr ();
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800309 }
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800310 version ++;
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800311
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -0800312 sqlite3_int64 seq_no = m_syncLog->GetNextLocalSeqNo ();
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800313
314 sqlite3_stmt *stmt;
315 sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800316 "(device_name, seq_no, action, filename, version, action_timestamp, "
317 "parent_device_name, parent_seq_no, "
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800318 "action_name, action_content_object) "
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800319 "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800320 " ?, ?,"
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800321 " ?, ?)", -1, &stmt, 0);
322
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800323 sqlite3_bind_blob (stmt, 1, device_name->buf (), device_name->length (), SQLITE_STATIC);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800324 sqlite3_bind_int64 (stmt, 2, seq_no);
325 sqlite3_bind_int (stmt, 3, 1);
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800326 sqlite3_bind_text (stmt, 4, filename.c_str (), filename.size (), SQLITE_STATIC); // file
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800327
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800328 sqlite3_bind_int64 (stmt, 5, version);
329 sqlite3_bind_int64 (stmt, 6, action_time);
330
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800331 sqlite3_bind_blob (stmt, 7, parent_device_name->buf (), parent_device_name->length (), SQLITE_STATIC);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800332 sqlite3_bind_int64 (stmt, 8, parent_seq_no);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800333
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800334 ActionItemPtr item = make_shared<ActionItem> ();
Alexander Afanasyev6d4befc2013-01-26 00:01:28 -0800335 item->set_action (ActionItem::DELETE);
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800336 item->set_filename (filename);
337 item->set_version (version);
338 item->set_timestamp (action_time);
339 item->set_parent_device_name (parent_device_name->buf (), parent_device_name->length ());
340 item->set_parent_seq_no (parent_seq_no);
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800341
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800342 string item_msg;
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800343 item->SerializeToString (&item_msg);
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -0800344
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800345 // action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq>
346 Name actionName = Name ("/")(m_syncLog->GetLocalName ())(m_appName)("action")(m_sharedFolderName)(seq_no);
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -0800347 _LOG_DEBUG ("ActionName: " << actionName);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800348
Alexander Afanasyevebf75182013-01-07 17:00:24 -0800349 Bytes actionData = m_ccnx->createContentObject (actionName, item_msg.c_str (), item_msg.size ());
350 CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf ();
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800351
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800352 sqlite3_bind_blob (stmt, 9, namePtr->buf (), namePtr->length (), SQLITE_STATIC);
353 sqlite3_bind_blob (stmt, 10, &actionData[0], actionData.size (), SQLITE_STATIC);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800354
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -0800355 sqlite3_step (stmt);
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800356
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800357 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800358
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800359 // cout << Ccnx::Name (parent_device_name) << endl;
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800360
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -0800361 // assign name to the action, serialize action, and create content object
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800362
363 sqlite3_finalize (stmt);
364
365 sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800366
367 return item;
Alexander Afanasyeva199f972013-01-02 19:37:26 -0800368}
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800369
370
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800371PcoPtr
372ActionLog::LookupActionPco (const Ccnx::Name &deviceName, sqlite3_int64 seqno)
373{
374 sqlite3_stmt *stmt;
375 sqlite3_prepare_v2 (m_db, "SELECT action_content_object FROM ActionLog WHERE device_name=? AND seq_no=?", -1, &stmt, 0);
376
377 CcnxCharbufPtr name = deviceName.toCcnxCharbuf ();
378
379 sqlite3_bind_blob (stmt, 1, name->buf (), name->length (), SQLITE_STATIC);
380 sqlite3_bind_int64 (stmt, 2, seqno);
381
382 PcoPtr retval;
383 if (sqlite3_step (stmt) == SQLITE_ROW)
384 {
385 // _LOG_DEBUG (sqlite3_column_blob (stmt, 0) << ", " << sqlite3_column_bytes (stmt, 0));
386 retval = make_shared<ParsedContentObject> (reinterpret_cast<const unsigned char *> (sqlite3_column_blob (stmt, 0)), sqlite3_column_bytes (stmt, 0));
387 }
388 else
389 {
390 _LOG_TRACE ("No action found for deviceName [" << deviceName << "] and seqno:" << seqno);
391 }
392 // _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK && sqlite3_errcode (m_db) != SQLITE_ROW, sqlite3_errmsg (m_db));
393 sqlite3_finalize (stmt);
394
395 return retval;
396}
397
398ActionItemPtr
399ActionLog::LookupAction (const Ccnx::Name &deviceName, sqlite3_int64 seqno)
400{
401 PcoPtr pco = LookupActionPco (deviceName, seqno);
402 if (!pco) return ActionItemPtr ();
403
404 ActionItemPtr action = deserializeMsg<ActionItem> (pco->content ());
405
406 return action;
407}
408
409Ccnx::PcoPtr
410ActionLog::LookupActionPco (const Ccnx::Name &actionName)
411{
412 sqlite3_stmt *stmt;
413 sqlite3_prepare_v2 (m_db, "SELECT action_content_object FROM ActionLog WHERE action_name=?", -1, &stmt, 0);
414
415 _LOG_DEBUG (actionName);
416 CcnxCharbufPtr name = actionName.toCcnxCharbuf ();
417
418 _LOG_DEBUG (" <<<<<<< " << name->buf () << " " << name->length ());
419
420 sqlite3_bind_blob (stmt, 1, name->buf (), name->length (), SQLITE_STATIC);
421
422 PcoPtr retval;
423 if (sqlite3_step (stmt) == SQLITE_ROW)
424 {
425 // _LOG_DEBUG (sqlite3_column_blob (stmt, 0) << ", " << sqlite3_column_bytes (stmt, 0));
426 retval = make_shared<ParsedContentObject> (reinterpret_cast<const unsigned char *> (sqlite3_column_blob (stmt, 0)), sqlite3_column_bytes (stmt, 0));
427 }
428 else
429 {
430 _LOG_TRACE ("No action found for name: " << actionName);
431 }
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800432 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_ROW, sqlite3_errmsg (m_db));
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800433 sqlite3_finalize (stmt);
434
435 return retval;
436}
437
438ActionItemPtr
439ActionLog::LookupAction (const Ccnx::Name &actionName)
440{
441 PcoPtr pco = LookupActionPco (actionName);
442 if (!pco) return ActionItemPtr ();
443
444 ActionItemPtr action = deserializeMsg<ActionItem> (pco->content ());
445
446 return action;
447}
448
Alexander Afanasyev026eaf32013-02-23 16:37:14 -0800449FileItemPtr
450ActionLog::LookupAction (const std::string &filename, sqlite3_int64 version, const Hash &filehash)
451{
452 sqlite3_stmt *stmt;
453 sqlite3_prepare_v2 (m_db,
454 "SELECT device_name, seq_no, file_mtime, file_chmod, file_seg_num, file_hash "
455 " FROM ActionLog "
456 " WHERE action = 0 AND "
457 " filename=? AND "
458 " version=? AND "
459 " is_prefix (?, file_hash)=1", -1, &stmt, 0);
460 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
461
462 sqlite3_bind_text (stmt, 1, filename.c_str (), filename.size (), SQLITE_STATIC);
463 sqlite3_bind_int64 (stmt, 2, version);
464 sqlite3_bind_blob (stmt, 3, filehash.GetHash (), filehash.GetHashBytes (), SQLITE_STATIC);
465
466 FileItemPtr fileItem;
467
468 if (sqlite3_step (stmt) == SQLITE_ROW)
469 {
470 fileItem = make_shared<FileItem> ();
471 fileItem->set_filename (filename);
472 fileItem->set_device_name (sqlite3_column_blob (stmt, 0), sqlite3_column_bytes (stmt, 0));
473 fileItem->set_seq_no (sqlite3_column_int64 (stmt, 1));
474 fileItem->set_mtime (sqlite3_column_int64 (stmt, 2));
475 fileItem->set_mode (sqlite3_column_int64 (stmt, 3));
476 fileItem->set_seg_num (sqlite3_column_int64 (stmt, 4));
477
478 fileItem->set_file_hash (sqlite3_column_blob (stmt, 5), sqlite3_column_bytes (stmt, 5));
479 }
480
481 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE || sqlite3_errcode (m_db) != SQLITE_ROW || sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
482
483 return fileItem;
484}
485
486
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800487ActionItemPtr
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800488ActionLog::AddRemoteAction (const Ccnx::Name &deviceName, sqlite3_int64 seqno, Ccnx::PcoPtr actionPco)
489{
490 if (!actionPco)
491 {
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800492 _LOG_ERROR ("actionPco is not valid");
493 return ActionItemPtr ();
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800494 }
495 ActionItemPtr action = deserializeMsg<ActionItem> (actionPco->content ());
496
497 if (!action)
498 {
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800499 _LOG_ERROR ("action cannot be decoded");
500 return ActionItemPtr ();
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800501 }
502
Alexander Afanasyevf695aed2013-01-30 13:28:42 -0800503 _LOG_DEBUG ("AddRemoteAction: [" << deviceName << "] seqno: " << seqno);
504
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800505 sqlite3_stmt *stmt;
506 int res = sqlite3_prepare_v2 (m_db, "INSERT INTO ActionLog "
507 "(device_name, seq_no, action, filename, version, action_timestamp, "
508 "file_hash, file_atime, file_mtime, file_ctime, file_chmod, file_seg_num, "
509 "parent_device_name, parent_seq_no, "
510 "action_name, action_content_object) "
511 "VALUES (?, ?, ?, ?, ?, datetime(?, 'unixepoch'),"
512 " ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?,?, "
513 " ?, ?, "
514 " ?, ?);", -1, &stmt, 0);
Alexander Afanasyevf695aed2013-01-30 13:28:42 -0800515 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800516
517 CcnxCharbufPtr device_name = deviceName.toCcnxCharbuf ();
518 sqlite3_bind_blob (stmt, 1, device_name->buf (), device_name->length (), SQLITE_STATIC);
519 sqlite3_bind_int64 (stmt, 2, seqno);
520
521 sqlite3_bind_int (stmt, 3, action->action ());
522 sqlite3_bind_text (stmt, 4, action->filename ().c_str (), action->filename ().size (), SQLITE_STATIC);
523 sqlite3_bind_int64 (stmt, 5, action->version ());
524 sqlite3_bind_int64 (stmt, 6, action->timestamp ());
525
526 if (action->action () == ActionItem::UPDATE)
527 {
528 sqlite3_bind_blob (stmt, 7, action->file_hash ().c_str (), action->file_hash ().size (), SQLITE_STATIC);
529
530 // sqlite3_bind_int64 (stmt, 8, atime); // NULL
531 sqlite3_bind_int64 (stmt, 9, action->mtime ());
532 // sqlite3_bind_int64 (stmt, 10, ctime); // NULL
533
534 sqlite3_bind_int (stmt, 11, action->mode ());
535 sqlite3_bind_int (stmt, 12, action->seg_num ());
536 }
537
538 if (action->has_parent_device_name ())
539 {
Alexander Afanasyev2b760d02013-02-07 13:47:29 -0800540 sqlite3_bind_blob (stmt, 13, action->parent_device_name ().c_str (), action->parent_device_name ().size (), SQLITE_STATIC);
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800541 sqlite3_bind_int64 (stmt, 14, action->parent_seq_no ());
542 }
543
544 Name actionName = Name (deviceName)("action")(m_sharedFolderName)(seqno);
545 CcnxCharbufPtr namePtr = actionName.toCcnxCharbuf ();
546
547 sqlite3_bind_blob (stmt, 15, namePtr->buf (), namePtr->length (), SQLITE_STATIC);
548 sqlite3_bind_blob (stmt, 16, head (actionPco->buf ()), actionPco->buf ().size (), SQLITE_STATIC);
549 sqlite3_step (stmt);
550
551 // if action needs to be applied to file state, the trigger will take care of it
552
Alexander Afanasyev0a30a0c2013-01-29 17:25:42 -0800553 _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800554
555 sqlite3_finalize (stmt);
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800556
557 return action;
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800558}
559
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800560ActionItemPtr
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800561ActionLog::AddRemoteAction (Ccnx::PcoPtr actionPco)
562{
563 Name name = actionPco->name ();
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800564 // action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq>
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800565
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800566 uint64_t seqno = name.getCompFromBackAsInt (0);
567 string sharedFolder = name.getCompFromBackAsString (1);
Alexander Afanasyev08aa70a2013-01-22 22:16:25 -0800568
569 if (sharedFolder != m_sharedFolderName)
570 {
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800571 _LOG_ERROR ("Action doesn't belong to this shared folder");
572 return ActionItemPtr ();
Alexander Afanasyev08aa70a2013-01-22 22:16:25 -0800573 }
574
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800575 string action = name.getCompFromBackAsString (2);
Alexander Afanasyev08aa70a2013-01-22 22:16:25 -0800576
577 if (action != "action")
578 {
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800579 _LOG_ERROR ("not an action");
580 return ActionItemPtr ();
Alexander Afanasyev08aa70a2013-01-22 22:16:25 -0800581 }
Alexander Afanasyev4d086752013-02-07 13:06:04 -0800582
583 string appName = name.getCompFromBackAsString (3);
584 if (appName != m_appName)
585 {
586 _LOG_ERROR ("Action doesn't belong to this application");
587 return ActionItemPtr ();
588 }
589
590 Name deviceName = name.getPartialName (0, name.size ()-4);
Alexander Afanasyev08aa70a2013-01-22 22:16:25 -0800591
592 _LOG_DEBUG ("From [" << name << "] extracted deviceName: " << deviceName << ", sharedFolder: " << sharedFolder << ", seqno: " << seqno);
593
Alexander Afanasyevf9978f82013-01-23 16:30:31 -0800594 return AddRemoteAction (deviceName, seqno, actionPco);
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800595}
596
Alexander Afanasyevf2c16e02013-01-23 18:08:04 -0800597sqlite3_int64
598ActionLog::LogSize ()
599{
600 sqlite3_stmt *stmt;
601 sqlite3_prepare_v2 (m_db, "SELECT count(*) FROM ActionLog", -1, &stmt, 0);
602
603 sqlite3_int64 retval = -1;
604 if (sqlite3_step (stmt) == SQLITE_ROW)
605 {
606 retval = sqlite3_column_int64 (stmt, 0);
607 }
608
609 return retval;
610}
611
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800612///////////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800613///////////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800614///////////////////////////////////////////////////////////////////////////////////
615
616void
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800617ActionLog::apply_action_xFun (sqlite3_context *context, int argc, sqlite3_value **argv)
618{
619 ActionLog *the = reinterpret_cast<ActionLog*> (sqlite3_user_data (context));
620
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800621 if (argc != 10)
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800622 {
Alexander Afanasyeva35756b2013-01-22 16:59:11 -0800623 sqlite3_result_error (context, "``apply_action'' expects 10 arguments", -1);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800624 return;
625 }
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800626
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800627 CcnxCharbuf device_name (sqlite3_value_blob (argv[0]), sqlite3_value_bytes (argv[0]));
628 sqlite3_int64 seq_no = sqlite3_value_int64 (argv[1]);
629 int action = sqlite3_value_int (argv[2]);
630 string filename = reinterpret_cast<const char*> (sqlite3_value_text (argv[3]));
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800631
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800632 _LOG_TRACE ("apply_function called with " << argc);
633 _LOG_TRACE ("device_name: " << Name (device_name)
634 << ", action: " << action
635 << ", file: " << filename);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800636
637 if (action == 0) // update
638 {
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800639 Hash hash (sqlite3_value_blob (argv[4]), sqlite3_value_bytes (argv[4]));
640 time_t atime = static_cast<time_t> (sqlite3_value_int64 (argv[5]));
641 time_t mtime = static_cast<time_t> (sqlite3_value_int64 (argv[6]));
642 time_t ctime = static_cast<time_t> (sqlite3_value_int64 (argv[7]));
643 int mode = sqlite3_value_int (argv[8]);
644 int seg_num = sqlite3_value_int (argv[9]);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800645
Alexander Afanasyev0995f322013-01-22 13:16:46 -0800646 _LOG_DEBUG ("Update " << filename << " " << atime << " " << mtime << " " << ctime << " " << hash);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800647
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800648 the->m_fileState->UpdateFile (filename, hash, device_name, seq_no, atime, mtime, ctime, mode, seg_num);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800649
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800650 // no callback here
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800651 }
652 else if (action == 1) // delete
653 {
Alexander Afanasyevd6364ef2013-02-06 13:13:07 -0800654 the->m_fileState->DeleteFile (filename);
Alexander Afanasyev0c545ed2013-01-26 00:12:32 -0800655
656 the->m_onFileRemoved (filename);
Alexander Afanasyeva2f77e92013-01-03 22:46:52 -0800657 }
Alexander Afanasyev49a30d02013-01-21 21:38:48 -0800658
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800659 sqlite3_result_null (context);
660}
Zhenkai Zhuc3fd51e2013-01-22 10:45:54 -0800661
Alexander Afanasyev7a647002013-01-30 11:54:52 -0800662