Changeset 2717 for box/trunk/bin/bbackupd/BackupClientInodeToIDMap.cpp
- Timestamp:
- 28/08/2010 10:01:16 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupd/BackupClientInodeToIDMap.cpp
r2631 r2717 11 11 12 12 #include <stdlib.h> 13 #include <depot.h> 13 14 #define _PUBLIC_ 15 #include "tdb.h" 14 16 15 17 #define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION … … 27 29 } IDBRecord; 28 30 29 #define BOX_DBM_MESSAGE(stuff) stuff << " ( qdbm): " << dperrmsg(dpecode)31 #define BOX_DBM_MESSAGE(stuff) stuff << " (tdb): " << tdb_error(mpContext) 30 32 31 33 #define BOX_LOG_DBM_ERROR(stuff) \ … … 37 39 BOX_DBM_MESSAGE(message << ": " << filename)); 38 40 39 #define ASSERT_DBM _OK(operation, message, filename, exception, subtype) \40 if(!( operation)) \41 #define ASSERT_DBM(success, message, exception, subtype) \ 42 if(!(success)) \ 41 43 { \ 42 THROW_DBM_ERROR(message, filename, exception, subtype); \44 THROW_DBM_ERROR(message, mFilename, exception, subtype); \ 43 45 } 44 46 45 47 #define ASSERT_DBM_OPEN() \ 46 if(mp Depot == 0) \48 if(mpContext == 0) \ 47 49 { \ 48 50 THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \ … … 51 53 52 54 #define ASSERT_DBM_CLOSED() \ 53 if(mp Depot != 0) \55 if(mpContext != 0) \ 54 56 { \ 55 57 THROW_EXCEPTION_MESSAGE(CommonException, Internal, \ … … 68 70 : mReadOnly(true), 69 71 mEmpty(false), 70 mp Depot(0)72 mpContext(NULL) 71 73 { 72 74 } … … 82 84 BackupClientInodeToIDMap::~BackupClientInodeToIDMap() 83 85 { 84 if(mp Depot != 0)86 if(mpContext != NULL) 85 87 { 86 88 Close(); … … 109 111 110 112 // Open the database file 111 int mode = ReadOnly ? DP_OREADER : DP_OWRITER;113 int mode = ReadOnly ? O_RDONLY : O_RDWR; 112 114 if(CreateNew) 113 115 { 114 mode |= DP_OCREAT;115 } 116 117 mp Depot = dpopen(Filename, mode,0);118 119 ASSERT_DBM _OK(mpDepot, "Failed to open inode database", mFilename,116 mode |= O_CREAT; 117 } 118 119 mpContext = tdb_open(Filename, 0, 0, mode, 0700); 120 121 ASSERT_DBM(mpContext != NULL, "Failed to open inode database", 120 122 BackupStoreException, BerkelyDBFailure); 121 123 … … 138 140 { 139 141 ASSERT_DBM_CLOSED(); 140 ASSERT(mp Depot == 0);142 ASSERT(mpContext == NULL); 141 143 mEmpty = true; 142 144 mReadOnly = true; … … 154 156 { 155 157 ASSERT_DBM_OPEN(); 156 ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database", 157 mFilename, BackupStoreException, BerkelyDBFailure); 158 mpDepot = 0; 159 } 158 ASSERT_DBM(tdb_close(mpContext) == 0, "Failed to close inode database", 159 BackupStoreException, BerkelyDBFailure); 160 mpContext = NULL; 161 } 162 163 static TDB_DATA GetDatum(void* dptr, size_t dsize) 164 { 165 TDB_DATA datum; 166 datum.dptr = (unsigned char *)dptr; 167 datum.dsize = dsize; 168 return datum; 169 } 170 171 #define GET_STRUCT_DATUM(structure) \ 172 GetDatum(&structure, sizeof(structure)) 160 173 161 174 // -------------------------------------------------------------------------- … … 177 190 } 178 191 179 if(mp Depot == 0)192 if(mpContext == 0) 180 193 { 181 194 THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); … … 189 202 rec.mInDirectory = InDirectory; 190 203 191 ASSERT_DBM _OK(dpput(mpDepot, (const char *)&InodeRef, sizeof(InodeRef),192 (const char *)&rec, sizeof(rec), DP_DOVER),193 "Failed to add record to inode database", mFilename,204 ASSERT_DBM(tdb_store(mpContext, GET_STRUCT_DATUM(InodeRef), 205 GET_STRUCT_DATUM(rec), 0) == 0, 206 "Failed to add record to inode database", 194 207 BackupStoreException, BerkelyDBFailure); 195 208 } … … 215 228 } 216 229 217 if(mp Depot == 0)230 if(mpContext == 0) 218 231 { 219 232 THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); … … 222 235 ASSERT_DBM_OPEN(); 223 236 224 IDBRecord rec; 225 226 if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), 227 0, sizeof(IDBRecord), (char *)&rec) == -1) 237 TDB_DATA datum = tdb_fetch(mpContext, GET_STRUCT_DATUM(InodeRef)); 238 if(datum.dptr == NULL) 228 239 { 229 240 // key not in file 230 241 return false; 231 242 } 243 244 IDBRecord rec; 245 if(datum.dsize != sizeof(rec)) 246 { 247 THROW_EXCEPTION_MESSAGE(CommonException, Internal, 248 "Failed to get inode database entry: " 249 "record has wrong size: expected " << 250 sizeof(rec) << " but was " << datum.dsize << 251 " in " << mFilename); 252 } 232 253 254 rec = *(IDBRecord *)datum.dptr; 255 free(datum.dptr); 256 233 257 // Return data 234 258 rObjectIDOut = rec.mObjectID;
Note: See TracChangeset
for help on using the changeset viewer.
