Permalink
Browse files

readonly support

  • Loading branch information...
1 parent 659060a commit c09be41d6ad257f605326823bef33b58d39d346e @albertz committed Mar 7, 2011
Showing with 7 additions and 2 deletions.
  1. +1 −0 Db.h
  2. +2 −1 DbKyotoBackend.cpp
  3. +3 −1 DbKyotoBackend.h
  4. +1 −0 db-list-dir.cpp
View
1 Db.h
@@ -64,6 +64,7 @@ struct DbDirEntry {
struct DbIntf {
DbStats stats;
+ virtual Return setReadOnly(bool ro) { return "Db::setReadOnly: not implemented"; }
virtual Return init() = 0;
virtual Return push(/*out*/ DbEntryId& id, const DbEntry& entry) = 0;
virtual Return get(/*out*/ DbEntry& entry, const DbEntryId& id) = 0;
View
3 DbKyotoBackend.cpp
@@ -13,10 +13,11 @@ using namespace std;
using namespace kyotocabinet;
DbKyotoBackend::~DbKyotoBackend() {
+ db.close();
}
Return DbKyotoBackend::init() {
- if(!db.open(filename, PolyDB::OWRITER | PolyDB::OCREATE))
+ if(!db.open(filename, readonly ? PolyDB::OREADER : (PolyDB::OWRITER | PolyDB::OCREATE)))
return std::string() + "failed to open KyotoCabinet DB: " + db.error().name();
return true;
}
View
4 DbKyotoBackend.h
@@ -12,9 +12,11 @@
struct DbKyotoBackend : DbIntf {
kyotocabinet::PolyDB db;
std::string filename;
+ bool readonly;
- DbKyotoBackend(const std::string& dbfilename = "db.kch") : filename(dbfilename) {}
+ DbKyotoBackend(const std::string& dbfilename = "db.kch", bool ro = false) : filename(dbfilename), readonly(ro) {}
~DbKyotoBackend();
+ Return setReadOnly(bool ro) { readonly = ro; return true; }
Return init();
Return push(/*out*/ DbEntryId& id, const DbEntry& entry);
Return get(/*out*/ DbEntry& entry, const DbEntryId& id);
View
1 db-list-dir.cpp
@@ -51,6 +51,7 @@ static Return listDir(const std::string& path) {
static Return _main() {
DbDefBackend dbInst;
db = &dbInst;
+ db->setReadOnly(true);
ASSERT( db->init() );
ASSERT( listDir("") );
return true;

0 comments on commit c09be41

Please sign in to comment.