Changeset 2794 for box/trunk/bin
- Timestamp:
- 18/10/2010 21:34:25 (19 months ago)
- Location:
- box/trunk/bin/bbackupd
- Files:
-
- 2 edited
-
BackupClientInodeToIDMap.cpp (modified) (13 diffs)
-
BackupClientInodeToIDMap.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupd/BackupClientInodeToIDMap.cpp
r2717 r2794 11 11 12 12 #include <stdlib.h> 13 14 #define _PUBLIC_ 15 #include "tdb.h" 13 #include <depot.h> 16 14 17 15 #define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION … … 29 27 } IDBRecord; 30 28 31 #define BOX_DBM_MESSAGE(stuff) stuff << " ( tdb): " << tdb_error(mpContext)29 #define BOX_DBM_MESSAGE(stuff) stuff << " (qdbm): " << dperrmsg(dpecode) 32 30 33 31 #define BOX_LOG_DBM_ERROR(stuff) \ … … 39 37 BOX_DBM_MESSAGE(message << ": " << filename)); 40 38 41 #define ASSERT_DBM (success, message, exception, subtype) \42 if(!( success)) \39 #define ASSERT_DBM_OK(operation, message, filename, exception, subtype) \ 40 if(!(operation)) \ 43 41 { \ 44 THROW_DBM_ERROR(message, mFilename, exception, subtype); \42 THROW_DBM_ERROR(message, filename, exception, subtype); \ 45 43 } 46 44 47 45 #define ASSERT_DBM_OPEN() \ 48 if(mp Context == 0) \46 if(mpDepot == 0) \ 49 47 { \ 50 48 THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \ … … 53 51 54 52 #define ASSERT_DBM_CLOSED() \ 55 if(mp Context != 0) \53 if(mpDepot != 0) \ 56 54 { \ 57 55 THROW_EXCEPTION_MESSAGE(CommonException, Internal, \ … … 70 68 : mReadOnly(true), 71 69 mEmpty(false), 72 mp Context(NULL)70 mpDepot(0) 73 71 { 74 72 } … … 84 82 BackupClientInodeToIDMap::~BackupClientInodeToIDMap() 85 83 { 86 if(mp Context != NULL)84 if(mpDepot != 0) 87 85 { 88 86 Close(); … … 111 109 112 110 // Open the database file 113 int mode = ReadOnly ? O_RDONLY : O_RDWR;111 int mode = ReadOnly ? DP_OREADER : DP_OWRITER; 114 112 if(CreateNew) 115 113 { 116 mode |= O_CREAT;117 } 118 119 mp Context = tdb_open(Filename, 0, 0, mode, 0700);120 121 ASSERT_DBM (mpContext != NULL, "Failed to open inode database",114 mode |= DP_OCREAT; 115 } 116 117 mpDepot = dpopen(Filename, mode, 0); 118 119 ASSERT_DBM_OK(mpDepot, "Failed to open inode database", mFilename, 122 120 BackupStoreException, BerkelyDBFailure); 123 121 … … 140 138 { 141 139 ASSERT_DBM_CLOSED(); 142 ASSERT(mp Context == NULL);140 ASSERT(mpDepot == 0); 143 141 mEmpty = true; 144 142 mReadOnly = true; … … 156 154 { 157 155 ASSERT_DBM_OPEN(); 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)) 156 ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database", 157 mFilename, BackupStoreException, BerkelyDBFailure); 158 mpDepot = 0; 159 } 173 160 174 161 // -------------------------------------------------------------------------- … … 190 177 } 191 178 192 if(mp Context == 0)179 if(mpDepot == 0) 193 180 { 194 181 THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); … … 202 189 rec.mInDirectory = InDirectory; 203 190 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", 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, 207 194 BackupStoreException, BerkelyDBFailure); 208 195 } … … 228 215 } 229 216 230 if(mp Context == 0)217 if(mpDepot == 0) 231 218 { 232 219 THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); … … 235 222 ASSERT_DBM_OPEN(); 236 223 237 TDB_DATA datum = tdb_fetch(mpContext, GET_STRUCT_DATUM(InodeRef)); 238 if(datum.dptr == NULL) 224 IDBRecord rec; 225 226 if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), 227 0, sizeof(IDBRecord), (char *)&rec) == -1) 239 228 { 240 229 // key not in file 241 230 return false; 242 231 } 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 }253 232 254 rec = *(IDBRecord *)datum.dptr;255 free(datum.dptr);256 257 233 // Return data 258 234 rObjectIDOut = rec.mObjectID; -
box/trunk/bin/bbackupd/BackupClientInodeToIDMap.h
r2717 r2794 18 18 // avoid having to include the DB files when not necessary 19 19 #ifndef BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION 20 struct TDB_CONTEXT; 21 struct TDB_DATUM; 20 class DEPOT; 22 21 #endif 23 22 … … 51 50 bool mEmpty; 52 51 std::string mFilename; 53 TDB_CONTEXT *mpContext;52 DEPOT *mpDepot; 54 53 }; 55 54
Note: See TracChangeset
for help on using the changeset viewer.
