projects
/
cumulus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use the subprocess module, not os.popen2, for Python 3 compatibility.
[cumulus.git]
/
localdb.cc
diff --git
a/localdb.cc
b/localdb.cc
index
0c9dac4
..
fd86605
100644
(file)
--- a/
localdb.cc
+++ b/
localdb.cc
@@
-32,12
+32,14
@@
#include <sqlite3.h>
#include <algorithm>
#include <sqlite3.h>
#include <algorithm>
+#include <map>
#include <string>
#include "localdb.h"
#include "store.h"
#include "util.h"
#include <string>
#include "localdb.h"
#include "store.h"
#include "util.h"
+using std::map;
using std::max;
using std::min;
using std::set;
using std::max;
using std::min;
using std::set;
@@
-319,7
+321,7
@@
bool LocalDb::IsOldObject(const string &checksum, int64_t size, double *age,
sqlite3_stmt *stmt;
bool found = false;
sqlite3_stmt *stmt;
bool found = false;
- stmt = Prepare("select segmentid, object,
timestamp
, expired "
+ stmt = Prepare("select segmentid, object,
julianday(timestamp)
, expired "
"from block_index where checksum = ? and size = ?");
sqlite3_bind_text(stmt, 1, checksum.c_str(), checksum.size(),
SQLITE_TRANSIENT);
"from block_index where checksum = ? and size = ?");
sqlite3_bind_text(stmt, 1, checksum.c_str(), checksum.size(),
SQLITE_TRANSIENT);
@@
-494,7
+496,8
@@
void LocalDb::SetSegmentMetadata(const std::string &segment,
stmt = Prepare("update segments set path = ?, checksum = ?, "
"type = ?, data_size = ?, disk_size = ?, "
stmt = Prepare("update segments set path = ?, checksum = ?, "
"type = ?, data_size = ?, disk_size = ?, "
- "mtime = coalesce(mtime, julianday('now')) "
+ "timestamp = coalesce(julianday(timestamp), "
+ " julianday('now')) "
"where segmentid = ?");
sqlite3_bind_text(stmt, 1, path.c_str(), path.size(),
SQLITE_TRANSIENT);
"where segmentid = ?");
sqlite3_bind_text(stmt, 1, path.c_str(), path.size(),
SQLITE_TRANSIENT);
@@
-515,36
+518,33
@@
void LocalDb::SetSegmentMetadata(const std::string &segment,
sqlite3_finalize(stmt);
}
sqlite3_finalize(stmt);
}
-bool LocalDb::GetSegmentMetadata(const string &segment,
- string *seg_path,
- string *seg_checksum)
+map<string, string> LocalDb::GetSegmentMetadata(const string &segment)
{
int rc;
sqlite3_stmt *stmt;
{
int rc;
sqlite3_stmt *stmt;
- ObjectReference ref;
- int found = false;
+ map<string, string> info;
+
+ // Names in the returned map, in the order returned from the select
+ // statement below.
+ static const char *fields[] = {
+ "datetime", "path", "checksum", "data_size", "disk_size", "type", NULL
+ };
- stmt = Prepare("select path, checksum from segments where segment = ?");
+ stmt = Prepare("select datetime(timestamp), path, checksum, "
+ " data_size, disk_size, type "
+ "from segments where segment = ?");
sqlite3_bind_text(stmt, 1, segment.c_str(), segment.size(),
SQLITE_TRANSIENT);
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE) {
} else if (rc == SQLITE_ROW) {
sqlite3_bind_text(stmt, 1, segment.c_str(), segment.size(),
SQLITE_TRANSIENT);
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE) {
} else if (rc == SQLITE_ROW) {
- found = true;
- const char *val;
-
- val = (const char *)sqlite3_column_text(stmt, 0);
- if (val == NULL)
- found = false;
- else
- *seg_path = val;
-
- val = (const char *)sqlite3_column_text(stmt, 1);
- if (val == NULL)
- found = false;
- else
- *seg_checksum = val;
+ info["segment"] = segment;
+ for (int i = 0; fields[i] != NULL; i++) {
+ const char *val = (const char *)sqlite3_column_text(stmt, i);
+ if (val != NULL)
+ info[fields[i]] = val;
+ }
} else {
fprintf(stderr, "Could not execute SELECT statement!\n");
ReportError(rc);
} else {
fprintf(stderr, "Could not execute SELECT statement!\n");
ReportError(rc);
@@
-552,7
+552,7
@@
bool LocalDb::GetSegmentMetadata(const string &segment,
sqlite3_finalize(stmt);
sqlite3_finalize(stmt);
- return
found
;
+ return
info
;
}
/* Look up and return the packed representation of the subblock chunk
}
/* Look up and return the packed representation of the subblock chunk