summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Mazieres <dm@uun.org>2014-02-07 18:38:58 -0800
committerDavid Mazieres <dm@uun.org>2014-02-07 18:38:58 -0800
commitfaa303a2d6aeb497fd8ca487b567fc7d4cfdfca3 (patch)
tree237a915e842ef5e62dabac51e47ef2b1a7bbd2da
parent9edc56c2d44f24ee89a835ee90133639dff6df33 (diff)
make sqlstmt_t copyable
-rw-r--r--maildir.cc10
-rw-r--r--sqlstmt.cc14
-rw-r--r--sqlstmt.h2
3 files changed, 18 insertions, 8 deletions
diff --git a/maildir.cc b/maildir.cc
index 4ee7c48..6f7e9cc 100644
--- a/maildir.cc
+++ b/maildir.cc
@@ -48,6 +48,9 @@ public:
" VALUES (?, ?, %lld, %lld);", ws.first, ws.second)
{
}
+ file_dbops(const file_dbops &l)
+ : del_file_(l.del_file_), add_file_(l.add_file_), upd_file_(l.upd_file_),
+ mod_hash_(l.mod_hash_), get_hash_(l.get_hash_), add_hash_(l.add_hash_) {}
i64 get_hash_id(const string &hash, i64 sz) {
lock_guard<mutex> _lk (m_);
@@ -268,7 +271,7 @@ scan_directory (const string &path, int dfd, i64 dir_id,
if (opt_verbose > 2)
cerr << " " << name << "\n";
- //wq.enqueue([path,cmp,mtim,inode,rowid,hash_id,name,dir_id,&fdb]() {
+ wq.enqueue([path,cmp,mtim,inode,rowid,hash_id,name,dir_id,&fdb]() {
i64 sz;
string hash = get_sha(AT_FDCWD, (path + "/" + name).c_str(), &sz);
i64 new_hash_id = fdb.get_hash_id(hash, sz);
@@ -277,9 +280,6 @@ scan_directory (const string &path, int dfd, i64 dir_id,
if (new_hash_id == hash_id) {
/* file unchanged; update metadata so we don't re-hash next time */
fdb.upd_file(rowid, mtim, inode);
- scan.step();
- f = f->fts_link;
- continue;
return;
}
cerr << "warning: " << path + "/" + name << " was modified\n";
@@ -287,7 +287,7 @@ scan_directory (const string &path, int dfd, i64 dir_id,
fdb.del_file(rowid, hash_id);
}
fdb.add_file(name.c_str(), mtim, inode, new_hash_id, dir_id);
- //});
+ });
scan.step();
f = f->fts_link;
}
diff --git a/sqlstmt.cc b/sqlstmt.cc
index e1035fa..eca932f 100644
--- a/sqlstmt.cc
+++ b/sqlstmt.cc
@@ -57,7 +57,7 @@ sqlstmt_t::sqlstmt_t (sqlite3 *db, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
- char *query = sqlite3_vmprintf (fmt, ap);
+ char *query = sqlite3_vmprintf(fmt, ap);
va_end (ap);
if (!query)
@@ -65,12 +65,22 @@ sqlstmt_t::sqlstmt_t (sqlite3 *db, const char *fmt, ...)
unique_ptr<char, decltype(&sqlite3_free)> _c (query, sqlite3_free);
const char *tail;
- if (sqlite3_prepare_v2 (db, query, -1, &stmt_, &tail))
+ if (sqlite3_prepare_v2(db, query, -1, &stmt_, &tail))
dbthrow (db, query);
if (tail && *tail)
throw sqlerr_t (string("illegal compound query\n Query: ") + query);
}
+sqlstmt_t::sqlstmt_t(const sqlstmt_t &l)
+{
+ int err = sqlite3_prepare_v2(sqlite3_db_handle(l.stmt_),
+ sqlite3_sql(l.stmt_), -1, &stmt_, nullptr);
+ if (err)
+ throw sqlerr_t (string("could not copy query\n Query: ")
+ + sqlite3_sql(l.stmt_) + "\n Error: "
+ + sqlite3_errstr(err) + "\n");
+}
+
void
sqlexec (sqlite3 *db, const char *fmt, ...)
{
diff --git a/sqlstmt.h b/sqlstmt.h
index 09a6c9a..2ae3941 100644
--- a/sqlstmt.h
+++ b/sqlstmt.h
@@ -25,7 +25,7 @@ class sqlstmt_t {
public:
explicit sqlstmt_t(sqlite3_stmt *stmt) : stmt_(stmt) {}
explicit sqlstmt_t(sqlite3 *db, const char *fmt, ...);
- sqlstmt_t(const sqlstmt_t &r) = delete;
+ sqlstmt_t(const sqlstmt_t &r);
sqlstmt_t(sqlstmt_t &&r) : stmt_ (r.stmt_) { r.stmt_ = nullptr; }
~sqlstmt_t() { sqlite3_finalize (stmt_); }