Update style to (almost) conform to ndn-cxx style using clang-format
diff --git a/src/file-state.cpp b/src/file-state.cpp
index 7904586..8ff065c 100644
--- a/src/file-state.cpp
+++ b/src/file-state.cpp
@@ -22,7 +22,7 @@
#include "logging.h"
#include <boost/bind.hpp>
-INIT_LOGGER ("FileState");
+INIT_LOGGER("FileState");
using namespace boost;
using namespace std;
@@ -51,122 +51,123 @@
CREATE INDEX FileState_type_file_hash ON FileState (type, file_hash); \n\
";
-FileState::FileState (const boost::filesystem::path &path, bool cow)
- : DbHelper (path / ".chronoshare", (cow ? "file-state-tmp.db" : "file-state.db"))
+FileState::FileState(const boost::filesystem::path& path)
+ : DbHelper(path / ".chronoshare", "file-state.db")
{
- sqlite3_exec (m_db, INIT_DATABASE.c_str (), NULL, NULL, NULL);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_exec(m_db, INIT_DATABASE.c_str(), NULL, NULL, NULL);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
}
-FileState::~FileState ()
+FileState::~FileState()
{
}
void
-FileState::UpdateFile (const std::string &filename, sqlite3_int64 version,
- const Hash &hash, const Ndnx::NdnxCharbuf &device_name, sqlite3_int64 seq_no,
- time_t atime, time_t mtime, time_t ctime, int mode, int seg_num)
+FileState::UpdateFile(const std::string& filename, sqlite3_int64 version, const Hash& hash,
+ const Ccnx::CcnxCharbuf& device_name, sqlite3_int64 seq_no, time_t atime,
+ time_t mtime, time_t ctime, int mode, int seg_num)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "UPDATE FileState "
- "SET "
- "device_name=?, seq_no=?, "
- "version=?,"
- "file_hash=?,"
- "file_atime=datetime(?, 'unixepoch'),"
- "file_mtime=datetime(?, 'unixepoch'),"
- "file_ctime=datetime(?, 'unixepoch'),"
- "file_chmod=?, "
- "file_seg_num=? "
- "WHERE type=0 AND filename=?", -1, &stmt, 0);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db, "UPDATE FileState "
+ "SET "
+ "device_name=?, seq_no=?, "
+ "version=?,"
+ "file_hash=?,"
+ "file_atime=datetime(?, 'unixepoch'),"
+ "file_mtime=datetime(?, 'unixepoch'),"
+ "file_ctime=datetime(?, 'unixepoch'),"
+ "file_chmod=?, "
+ "file_seg_num=? "
+ "WHERE type=0 AND filename=?",
+ -1, &stmt, 0);
- sqlite3_bind_blob (stmt, 1, device_name.buf (), device_name.length (), SQLITE_STATIC);
- sqlite3_bind_int64 (stmt, 2, seq_no);
- sqlite3_bind_int64 (stmt, 3, version);
- sqlite3_bind_blob (stmt, 4, hash.GetHash (), hash.GetHashBytes (), SQLITE_STATIC);
- 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_bind_int (stmt, 9, seg_num);
- sqlite3_bind_text (stmt, 10, filename.c_str (), -1, SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 1, device_name.buf(), device_name.length(), SQLITE_STATIC);
+ sqlite3_bind_int64(stmt, 2, seq_no);
+ sqlite3_bind_int64(stmt, 3, version);
+ sqlite3_bind_blob(stmt, 4, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ 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_bind_int(stmt, 9, seg_num);
+ sqlite3_bind_text(stmt, 10, filename.c_str(), -1, SQLITE_STATIC);
- sqlite3_step (stmt);
+ sqlite3_step(stmt);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_ROW && sqlite3_errcode (m_db) != SQLITE_DONE,
- sqlite3_errmsg (m_db));
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_ROW && sqlite3_errcode(m_db) != SQLITE_DONE,
+ sqlite3_errmsg(m_db));
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
- int affected_rows = sqlite3_changes (m_db);
+ int affected_rows = sqlite3_changes(m_db);
if (affected_rows == 0) // file didn't exist
- {
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "INSERT INTO FileState "
- "(type,filename,version,device_name,seq_no,file_hash,file_atime,file_mtime,file_ctime,file_chmod,file_seg_num) "
- "VALUES (0, ?, ?, ?, ?, ?, "
- "datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?, ?)", -1, &stmt, 0);
+ {
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "INSERT INTO FileState "
+ "(type,filename,version,device_name,seq_no,file_hash,file_atime,file_mtime,file_ctime,file_chmod,file_seg_num) "
+ "VALUES (0, ?, ?, ?, ?, ?, "
+ "datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?, ?)",
+ -1, &stmt, 0);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_text (stmt, 1, filename.c_str (), -1, SQLITE_STATIC);
- sqlite3_bind_int64 (stmt, 2, version);
- sqlite3_bind_blob (stmt, 3, device_name.buf (), device_name.length (), SQLITE_STATIC);
- sqlite3_bind_int64 (stmt, 4, seq_no);
- sqlite3_bind_blob (stmt, 5, hash.GetHash (), hash.GetHashBytes (), SQLITE_STATIC);
- sqlite3_bind_int64 (stmt, 6, atime);
- sqlite3_bind_int64 (stmt, 7, mtime);
- sqlite3_bind_int64 (stmt, 8, ctime);
- sqlite3_bind_int (stmt, 9, mode);
- sqlite3_bind_int (stmt, 10, seg_num);
+ sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
+ sqlite3_bind_int64(stmt, 2, version);
+ sqlite3_bind_blob(stmt, 3, device_name.buf(), device_name.length(), SQLITE_STATIC);
+ sqlite3_bind_int64(stmt, 4, seq_no);
+ sqlite3_bind_blob(stmt, 5, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ sqlite3_bind_int64(stmt, 6, atime);
+ sqlite3_bind_int64(stmt, 7, mtime);
+ sqlite3_bind_int64(stmt, 8, ctime);
+ sqlite3_bind_int(stmt, 9, mode);
+ sqlite3_bind_int(stmt, 10, seg_num);
- sqlite3_step (stmt);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE,
- sqlite3_errmsg (m_db));
- sqlite3_finalize (stmt);
+ sqlite3_step(stmt);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
+ sqlite3_finalize(stmt);
- sqlite3_prepare_v2 (m_db, "UPDATE FileState SET directory=directory_name(filename) WHERE filename=?", -1, &stmt, 0);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_prepare_v2(m_db,
+ "UPDATE FileState SET directory=directory_name(filename) WHERE filename=?",
+ -1, &stmt, 0);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_text (stmt, 1, filename.c_str (), -1, SQLITE_STATIC);
- sqlite3_step (stmt);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE,
- sqlite3_errmsg (m_db));
- sqlite3_finalize (stmt);
- }
+ sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
+ sqlite3_step(stmt);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
+ sqlite3_finalize(stmt);
+ }
}
void
-FileState::DeleteFile (const std::string &filename)
+FileState::DeleteFile(const std::string& filename)
{
-
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db, "DELETE FROM FileState WHERE type=0 AND filename=?", -1, &stmt, 0);
- sqlite3_bind_text (stmt, 1, filename.c_str (), -1, SQLITE_STATIC);
-
- _LOG_DEBUG ("Delete " << filename);
-
- sqlite3_step (stmt);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE,
- sqlite3_errmsg (m_db));
- sqlite3_finalize (stmt);
-}
-
-
-void
-FileState::SetFileComplete (const std::string &filename)
-{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "UPDATE FileState SET is_complete=1 WHERE type = 0 AND filename = ?", -1, &stmt, 0);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db, "DELETE FROM FileState WHERE type=0 AND filename=?", -1, &stmt, 0);
sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
- sqlite3_step (stmt);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
+ _LOG_DEBUG("Delete " << filename);
- sqlite3_finalize (stmt);
+ sqlite3_step(stmt);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
+ sqlite3_finalize(stmt);
+}
+
+
+void
+FileState::SetFileComplete(const std::string& filename)
+{
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db, "UPDATE FileState SET is_complete=1 WHERE type = 0 AND filename = ?", -1,
+ &stmt, 0);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
+ sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
+
+ sqlite3_step(stmt);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
+
+ sqlite3_finalize(stmt);
}
@@ -174,191 +175,199 @@
* @todo Implement checking modification time and permissions
*/
FileItemPtr
-FileState::LookupFile (const std::string &filename)
+FileState::LookupFile(const std::string& filename)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
- " FROM FileState "
- " WHERE type = 0 AND filename = ?", -1, &stmt, 0);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
+ " FROM FileState "
+ " WHERE type = 0 AND filename = ?",
+ -1, &stmt, 0);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
FileItemPtr retval;
- if (sqlite3_step (stmt) == SQLITE_ROW)
- {
- retval = make_shared<FileItem> ();
- retval->set_filename (reinterpret_cast<const char *> (sqlite3_column_text (stmt, 0)), sqlite3_column_bytes (stmt, 0));
- retval->set_version (sqlite3_column_int64 (stmt, 1));
- retval->set_device_name (sqlite3_column_blob (stmt, 2), sqlite3_column_bytes (stmt, 2));
- retval->set_seq_no (sqlite3_column_int64 (stmt, 3));
- retval->set_file_hash (sqlite3_column_blob (stmt, 4), sqlite3_column_bytes (stmt, 4));
- retval->set_mtime (sqlite3_column_int (stmt, 5));
- retval->set_mode (sqlite3_column_int (stmt, 6));
- retval->set_seg_num (sqlite3_column_int64 (stmt, 7));
- retval->set_is_complete (sqlite3_column_int (stmt, 8));
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
+ retval = make_shared<FileItem>();
+ retval->set_filename(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0));
+ retval->set_version(sqlite3_column_int64(stmt, 1));
+ retval->set_device_name(sqlite3_column_blob(stmt, 2), sqlite3_column_bytes(stmt, 2));
+ retval->set_seq_no(sqlite3_column_int64(stmt, 3));
+ retval->set_file_hash(sqlite3_column_blob(stmt, 4), sqlite3_column_bytes(stmt, 4));
+ retval->set_mtime(sqlite3_column_int(stmt, 5));
+ retval->set_mode(sqlite3_column_int(stmt, 6));
+ retval->set_seg_num(sqlite3_column_int64(stmt, 7));
+ retval->set_is_complete(sqlite3_column_int(stmt, 8));
}
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
- sqlite3_finalize (stmt);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
+ sqlite3_finalize(stmt);
return retval;
}
FileItemsPtr
-FileState::LookupFilesForHash (const Hash &hash)
+FileState::LookupFilesForHash(const Hash& hash)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
- " FROM FileState "
- " WHERE type = 0 AND file_hash = ?", -1, &stmt, 0);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
- sqlite3_bind_blob(stmt, 1, hash.GetHash (), hash.GetHashBytes (), SQLITE_STATIC);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
+ " FROM FileState "
+ " WHERE type = 0 AND file_hash = ?",
+ -1, &stmt, 0);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
+ sqlite3_bind_blob(stmt, 1, hash.GetHash(), hash.GetHashBytes(), SQLITE_STATIC);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- FileItemsPtr retval = make_shared<FileItems> ();
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- FileItem file;
- file.set_filename (reinterpret_cast<const char *> (sqlite3_column_text (stmt, 0)), sqlite3_column_bytes (stmt, 0));
- file.set_version (sqlite3_column_int64 (stmt, 1));
- file.set_device_name (sqlite3_column_blob (stmt, 2), sqlite3_column_bytes (stmt, 2));
- file.set_seq_no (sqlite3_column_int64 (stmt, 3));
- file.set_file_hash (sqlite3_column_blob (stmt, 4), sqlite3_column_bytes (stmt, 4));
- file.set_mtime (sqlite3_column_int (stmt, 5));
- file.set_mode (sqlite3_column_int (stmt, 6));
- file.set_seg_num (sqlite3_column_int64 (stmt, 7));
- file.set_is_complete (sqlite3_column_int (stmt, 8));
+ FileItemsPtr retval = make_shared<FileItems>();
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ FileItem file;
+ file.set_filename(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0));
+ file.set_version(sqlite3_column_int64(stmt, 1));
+ file.set_device_name(sqlite3_column_blob(stmt, 2), sqlite3_column_bytes(stmt, 2));
+ file.set_seq_no(sqlite3_column_int64(stmt, 3));
+ file.set_file_hash(sqlite3_column_blob(stmt, 4), sqlite3_column_bytes(stmt, 4));
+ file.set_mtime(sqlite3_column_int(stmt, 5));
+ file.set_mode(sqlite3_column_int(stmt, 6));
+ file.set_seg_num(sqlite3_column_int64(stmt, 7));
+ file.set_is_complete(sqlite3_column_int(stmt, 8));
- retval->push_back (file);
- }
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
+ retval->push_back(file);
+ }
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
return retval;
}
void
-FileState::LookupFilesInFolder (const boost::function<void (const FileItem&)> &visitor, const std::string &folder, int offset/*=0*/, int limit/*=-1*/)
+FileState::LookupFilesInFolder(const boost::function<void(const FileItem&)>& visitor,
+ const std::string& folder, int offset /*=0*/, int limit /*=-1*/)
{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2 (m_db,
- "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
- " FROM FileState "
- " WHERE type = 0 AND directory = ?"
- " LIMIT ? OFFSET ?", -1, &stmt, 0);
- if (folder.size () == 0)
- sqlite3_bind_null (stmt, 1);
+ sqlite3_stmt* stmt;
+ sqlite3_prepare_v2(m_db,
+ "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
+ " FROM FileState "
+ " WHERE type = 0 AND directory = ?"
+ " LIMIT ? OFFSET ?",
+ -1, &stmt, 0);
+ if (folder.size() == 0)
+ sqlite3_bind_null(stmt, 1);
else
- sqlite3_bind_text (stmt, 1, folder.c_str (), folder.size (), SQLITE_STATIC);
+ sqlite3_bind_text(stmt, 1, folder.c_str(), folder.size(), SQLITE_STATIC);
- sqlite3_bind_int (stmt, 2, limit);
- sqlite3_bind_int (stmt, 3, offset);
+ sqlite3_bind_int(stmt, 2, limit);
+ sqlite3_bind_int(stmt, 3, offset);
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- FileItem file;
- file.set_filename (reinterpret_cast<const char *> (sqlite3_column_text (stmt, 0)), sqlite3_column_bytes (stmt, 0));
- file.set_version (sqlite3_column_int64 (stmt, 1));
- file.set_device_name (sqlite3_column_blob (stmt, 2), sqlite3_column_bytes (stmt, 2));
- file.set_seq_no (sqlite3_column_int64 (stmt, 3));
- file.set_file_hash (sqlite3_column_blob (stmt, 4), sqlite3_column_bytes (stmt, 4));
- file.set_mtime (sqlite3_column_int (stmt, 5));
- file.set_mode (sqlite3_column_int (stmt, 6));
- file.set_seg_num (sqlite3_column_int64 (stmt, 7));
- file.set_is_complete (sqlite3_column_int (stmt, 8));
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ FileItem file;
+ file.set_filename(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0));
+ file.set_version(sqlite3_column_int64(stmt, 1));
+ file.set_device_name(sqlite3_column_blob(stmt, 2), sqlite3_column_bytes(stmt, 2));
+ file.set_seq_no(sqlite3_column_int64(stmt, 3));
+ file.set_file_hash(sqlite3_column_blob(stmt, 4), sqlite3_column_bytes(stmt, 4));
+ file.set_mtime(sqlite3_column_int(stmt, 5));
+ file.set_mode(sqlite3_column_int(stmt, 6));
+ file.set_seg_num(sqlite3_column_int64(stmt, 7));
+ file.set_is_complete(sqlite3_column_int(stmt, 8));
- visitor (file);
- }
+ visitor(file);
+ }
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
}
FileItemsPtr
-FileState::LookupFilesInFolder (const std::string &folder, int offset/*=0*/, int limit/*=-1*/)
+FileState::LookupFilesInFolder(const std::string& folder, int offset /*=0*/, int limit /*=-1*/)
{
- FileItemsPtr retval = make_shared<FileItems> ();
- LookupFilesInFolder (boost::bind (&FileItems::push_back, retval.get (), _1), folder, offset, limit);
+ FileItemsPtr retval = make_shared<FileItems>();
+ LookupFilesInFolder(boost::bind(&FileItems::push_back, retval.get(), _1), folder, offset, limit);
return retval;
}
bool
-FileState::LookupFilesInFolderRecursively (const boost::function<void (const FileItem&)> &visitor, const std::string &folder, int offset/*=0*/, int limit/*=-1*/)
+FileState::LookupFilesInFolderRecursively(const boost::function<void(const FileItem&)>& visitor,
+ const std::string& folder, int offset /*=0*/,
+ int limit /*=-1*/)
{
- _LOG_DEBUG ("LookupFilesInFolderRecursively: [" << folder << "]");
+ _LOG_DEBUG("LookupFilesInFolderRecursively: [" << folder << "]");
if (limit >= 0)
- limit ++;
+ limit++;
- sqlite3_stmt *stmt;
- if (folder != "")
- {
- /// @todo Do something to improve efficiency of this query. Right now it is basically scanning the whole database
+ sqlite3_stmt* stmt;
+ if (folder != "") {
+ /// @todo Do something to improve efficiency of this query. Right now it is basically scanning the whole database
- sqlite3_prepare_v2 (m_db,
- "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
- " FROM FileState "
- " WHERE type = 0 AND is_dir_prefix (?, directory)=1 "
- " ORDER BY filename "
- " LIMIT ? OFFSET ?", -1, &stmt, 0); // there is a small ambiguity with is_prefix matching, but should be ok for now
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_prepare_v2(m_db,
+ "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
+ " FROM FileState "
+ " WHERE type = 0 AND is_dir_prefix (?, directory)=1 "
+ " ORDER BY filename "
+ " LIMIT ? OFFSET ?",
+ -1, &stmt,
+ 0); // there is a small ambiguity with is_prefix matching, but should be ok for now
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_text (stmt, 1, folder.c_str (), folder.size (), SQLITE_STATIC);
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_bind_text(stmt, 1, folder.c_str(), folder.size(), SQLITE_STATIC);
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- sqlite3_bind_int (stmt, 2, limit);
- sqlite3_bind_int (stmt, 3, offset);
- }
- else
- {
- sqlite3_prepare_v2 (m_db,
- "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
- " FROM FileState "
- " WHERE type = 0"
- " ORDER BY filename "
- " LIMIT ? OFFSET ?", -1, &stmt, 0);
- sqlite3_bind_int (stmt, 1, limit);
- sqlite3_bind_int (stmt, 2, offset);
- }
+ sqlite3_bind_int(stmt, 2, limit);
+ sqlite3_bind_int(stmt, 3, offset);
+ }
+ else {
+ sqlite3_prepare_v2(m_db,
+ "SELECT filename,version,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,is_complete "
+ " FROM FileState "
+ " WHERE type = 0"
+ " ORDER BY filename "
+ " LIMIT ? OFFSET ?",
+ -1, &stmt, 0);
+ sqlite3_bind_int(stmt, 1, limit);
+ sqlite3_bind_int(stmt, 2, offset);
+ }
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
- while (sqlite3_step (stmt) == SQLITE_ROW)
- {
- if (limit == 1)
- break;
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ if (limit == 1)
+ break;
- FileItem file;
- file.set_filename (reinterpret_cast<const char *> (sqlite3_column_text (stmt, 0)), sqlite3_column_bytes (stmt, 0));
- file.set_version (sqlite3_column_int64 (stmt, 1));
- file.set_device_name (sqlite3_column_blob (stmt, 2), sqlite3_column_bytes (stmt, 2));
- file.set_seq_no (sqlite3_column_int64 (stmt, 3));
- file.set_file_hash (sqlite3_column_blob (stmt, 4), sqlite3_column_bytes (stmt, 4));
- file.set_mtime (sqlite3_column_int (stmt, 5));
- file.set_mode (sqlite3_column_int (stmt, 6));
- file.set_seg_num (sqlite3_column_int64 (stmt, 7));
- file.set_is_complete (sqlite3_column_int (stmt, 8));
+ FileItem file;
+ file.set_filename(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)),
+ sqlite3_column_bytes(stmt, 0));
+ file.set_version(sqlite3_column_int64(stmt, 1));
+ file.set_device_name(sqlite3_column_blob(stmt, 2), sqlite3_column_bytes(stmt, 2));
+ file.set_seq_no(sqlite3_column_int64(stmt, 3));
+ file.set_file_hash(sqlite3_column_blob(stmt, 4), sqlite3_column_bytes(stmt, 4));
+ file.set_mtime(sqlite3_column_int(stmt, 5));
+ file.set_mode(sqlite3_column_int(stmt, 6));
+ file.set_seg_num(sqlite3_column_int64(stmt, 7));
+ file.set_is_complete(sqlite3_column_int(stmt, 8));
- visitor (file);
- limit --;
- }
+ visitor(file);
+ limit--;
+ }
- _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db));
- sqlite3_finalize (stmt);
+ sqlite3_finalize(stmt);
return (limit == 1);
}
FileItemsPtr
-FileState::LookupFilesInFolderRecursively (const std::string &folder, int offset/*=0*/, int limit/*=-1*/)
+FileState::LookupFilesInFolderRecursively(const std::string& folder, int offset /*=0*/,
+ int limit /*=-1*/)
{
- FileItemsPtr retval = make_shared<FileItems> ();
- LookupFilesInFolder (boost::bind (&FileItems::push_back, retval.get (), _1), folder, offset, limit);
+ FileItemsPtr retval = make_shared<FileItems>();
+ LookupFilesInFolder(boost::bind(&FileItems::push_back, retval.get(), _1), folder, offset, limit);
return retval;
}