summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2010-10-18 20:34:25 +0000
committerChris Wilson <chris+github@qwirx.com>2010-10-18 20:34:25 +0000
commitcd154e05f09a5bd40e258f50a71e89d263143e35 (patch)
treefacb5de5351f04d00c32b0504291f68eb8890b26 /bin
parenta1f32183837c489dae93a1813653288e41c60f70 (diff)
Revert [2710] and [2717], remove TDB and replace with QDBM again, to fix
build on Windows and make it easier to merge Charles' work.
Diffstat (limited to 'bin')
-rw-r--r--bin/bbackupd/BackupClientInodeToIDMap.cpp76
-rw-r--r--bin/bbackupd/BackupClientInodeToIDMap.h5
2 files changed, 28 insertions, 53 deletions
diff --git a/bin/bbackupd/BackupClientInodeToIDMap.cpp b/bin/bbackupd/BackupClientInodeToIDMap.cpp
index 262e5bc2..74d5f3cd 100644
--- a/bin/bbackupd/BackupClientInodeToIDMap.cpp
+++ b/bin/bbackupd/BackupClientInodeToIDMap.cpp
@@ -10,9 +10,7 @@
#include "Box.h"
#include <stdlib.h>
-
-#define _PUBLIC_
-#include "tdb.h"
+#include <depot.h>
#define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION
#include "BackupClientInodeToIDMap.h"
@@ -28,7 +26,7 @@ typedef struct
int64_t mInDirectory;
} IDBRecord;
-#define BOX_DBM_MESSAGE(stuff) stuff << " (tdb): " << tdb_error(mpContext)
+#define BOX_DBM_MESSAGE(stuff) stuff << " (qdbm): " << dperrmsg(dpecode)
#define BOX_LOG_DBM_ERROR(stuff) \
BOX_ERROR(BOX_DBM_MESSAGE(stuff))
@@ -38,21 +36,21 @@ typedef struct
THROW_EXCEPTION_MESSAGE(exception, subtype, \
BOX_DBM_MESSAGE(message << ": " << filename));
-#define ASSERT_DBM(success, message, exception, subtype) \
- if(!(success)) \
+#define ASSERT_DBM_OK(operation, message, filename, exception, subtype) \
+ if(!(operation)) \
{ \
- THROW_DBM_ERROR(message, mFilename, exception, subtype); \
+ THROW_DBM_ERROR(message, filename, exception, subtype); \
}
#define ASSERT_DBM_OPEN() \
- if(mpContext == 0) \
+ if(mpDepot == 0) \
{ \
THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \
"Inode database not open"); \
}
#define ASSERT_DBM_CLOSED() \
- if(mpContext != 0) \
+ if(mpDepot != 0) \
{ \
THROW_EXCEPTION_MESSAGE(CommonException, Internal, \
"Inode database already open: " << mFilename); \
@@ -69,7 +67,7 @@ typedef struct
BackupClientInodeToIDMap::BackupClientInodeToIDMap()
: mReadOnly(true),
mEmpty(false),
- mpContext(NULL)
+ mpDepot(0)
{
}
@@ -83,7 +81,7 @@ BackupClientInodeToIDMap::BackupClientInodeToIDMap()
// --------------------------------------------------------------------------
BackupClientInodeToIDMap::~BackupClientInodeToIDMap()
{
- if(mpContext != NULL)
+ if(mpDepot != 0)
{
Close();
}
@@ -110,15 +108,15 @@ void BackupClientInodeToIDMap::Open(const char *Filename, bool ReadOnly,
ASSERT(!mEmpty);
// Open the database file
- int mode = ReadOnly ? O_RDONLY : O_RDWR;
+ int mode = ReadOnly ? DP_OREADER : DP_OWRITER;
if(CreateNew)
{
- mode |= O_CREAT;
+ mode |= DP_OCREAT;
}
- mpContext = tdb_open(Filename, 0, 0, mode, 0700);
+ mpDepot = dpopen(Filename, mode, 0);
- ASSERT_DBM(mpContext != NULL, "Failed to open inode database",
+ ASSERT_DBM_OK(mpDepot, "Failed to open inode database", mFilename,
BackupStoreException, BerkelyDBFailure);
// Read only flag
@@ -139,7 +137,7 @@ void BackupClientInodeToIDMap::Open(const char *Filename, bool ReadOnly,
void BackupClientInodeToIDMap::OpenEmpty()
{
ASSERT_DBM_CLOSED();
- ASSERT(mpContext == NULL);
+ ASSERT(mpDepot == 0);
mEmpty = true;
mReadOnly = true;
}
@@ -155,22 +153,11 @@ void BackupClientInodeToIDMap::OpenEmpty()
void BackupClientInodeToIDMap::Close()
{
ASSERT_DBM_OPEN();
- ASSERT_DBM(tdb_close(mpContext) == 0, "Failed to close inode database",
- BackupStoreException, BerkelyDBFailure);
- mpContext = NULL;
+ ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database",
+ mFilename, BackupStoreException, BerkelyDBFailure);
+ mpDepot = 0;
}
-static TDB_DATA GetDatum(void* dptr, size_t dsize)
-{
- TDB_DATA datum;
- datum.dptr = (unsigned char *)dptr;
- datum.dsize = dsize;
- return datum;
-}
-
-#define GET_STRUCT_DATUM(structure) \
- GetDatum(&structure, sizeof(structure))
-
// --------------------------------------------------------------------------
//
// Function
@@ -189,7 +176,7 @@ void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID,
THROW_EXCEPTION(BackupStoreException, InodeMapIsReadOnly);
}
- if(mpContext == 0)
+ if(mpDepot == 0)
{
THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen);
}
@@ -201,9 +188,9 @@ void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID,
rec.mObjectID = ObjectID;
rec.mInDirectory = InDirectory;
- ASSERT_DBM(tdb_store(mpContext, GET_STRUCT_DATUM(InodeRef),
- GET_STRUCT_DATUM(rec), 0) == 0,
- "Failed to add record to inode database",
+ ASSERT_DBM_OK(dpput(mpDepot, (const char *)&InodeRef, sizeof(InodeRef),
+ (const char *)&rec, sizeof(rec), DP_DOVER),
+ "Failed to add record to inode database", mFilename,
BackupStoreException, BerkelyDBFailure);
}
@@ -227,33 +214,22 @@ bool BackupClientInodeToIDMap::Lookup(InodeRefType InodeRef,
return false;
}
- if(mpContext == 0)
+ if(mpDepot == 0)
{
THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen);
}
ASSERT_DBM_OPEN();
- TDB_DATA datum = tdb_fetch(mpContext, GET_STRUCT_DATUM(InodeRef));
- if(datum.dptr == NULL)
+ IDBRecord rec;
+
+ if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef),
+ 0, sizeof(IDBRecord), (char *)&rec) == -1)
{
// key not in file
return false;
}
-
- IDBRecord rec;
- if(datum.dsize != sizeof(rec))
- {
- THROW_EXCEPTION_MESSAGE(CommonException, Internal,
- "Failed to get inode database entry: "
- "record has wrong size: expected " <<
- sizeof(rec) << " but was " << datum.dsize <<
- " in " << mFilename);
- }
- rec = *(IDBRecord *)datum.dptr;
- free(datum.dptr);
-
// Return data
rObjectIDOut = rec.mObjectID;
rInDirectoryOut = rec.mInDirectory;
diff --git a/bin/bbackupd/BackupClientInodeToIDMap.h b/bin/bbackupd/BackupClientInodeToIDMap.h
index f47c7a54..fbe45114 100644
--- a/bin/bbackupd/BackupClientInodeToIDMap.h
+++ b/bin/bbackupd/BackupClientInodeToIDMap.h
@@ -17,8 +17,7 @@
// avoid having to include the DB files when not necessary
#ifndef BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION
- struct TDB_CONTEXT;
- struct TDB_DATUM;
+ class DEPOT;
#endif
// --------------------------------------------------------------------------
@@ -50,7 +49,7 @@ private:
bool mReadOnly;
bool mEmpty;
std::string mFilename;
- TDB_CONTEXT *mpContext;
+ DEPOT *mpDepot;
};
#endif // BACKUPCLIENTINODETOIDMAP_H