Changeset 3081
- Timestamp:
- 02/02/2012 22:18:44 (4 months ago)
- Location:
- box/trunk/bin/bbackupd
- Files:
-
- 2 edited
-
BackupDaemon.cpp (modified) (19 diffs)
-
BackupDaemon.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupd/BackupDaemon.cpp
r3032 r3081 325 325 { 326 326 // Run through, and delete everything 327 for( std::vector<Location *>::iterator i = mLocations.begin();327 for(Locations::iterator i = mLocations.begin(); 328 328 i != mLocations.end(); ++i) 329 329 { … … 965 965 // need to do it here so we have a 966 966 // (potential) connection to use 967 if(mLocations.empty())968 967 { 969 968 const Configuration &locations( … … 989 988 990 989 // Go through the records, syncing them 991 for( std::vector<Location *>::const_iterator990 for(Locations::const_iterator 992 991 i(mLocations.begin()); 993 992 i != mLocations.end(); ++i) … … 1036 1035 mClientStoreMarker = clientContext.GetClientStoreMarker(); 1037 1036 mStorageLimitExceeded = clientContext.StorageLimitExceeded(); 1038 mReadErrorsOnFilesystemObjects =1037 mReadErrorsOnFilesystemObjects |= 1039 1038 params.mReadErrorsOnFilesystemObjects; 1040 1039 … … 2105 2104 void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Configuration &rLocationsConf) 2106 2105 { 2107 if(!mLocations.empty())2108 {2109 // Looks correctly set up2110 return;2111 }2112 2113 // Make sure that if a directory is reinstated, then it doesn't get deleted2114 mDeleteUnusedRootDirEntriesAfter = 0;2115 mUnusedRootDirEntries.clear();2116 2117 // Just a check to make sure it's right.2118 DeleteAllLocations();2119 2120 2106 // Going to need a copy of the root directory. Get a connection, 2121 2107 // and fetch it. … … 2224 2210 std::vector<std::string> locNames = 2225 2211 rLocationsConf.GetSubConfigurationNames(); 2226 2212 2213 // We only want completely configured locations to be in the list 2214 // when this function exits, so move them all to a temporary list. 2215 // Entries matching a properly configured location will be moved 2216 // back to mLocations. Anything left in this list after the loop 2217 // finishes will be deleted. 2218 Locations tmpLocations = mLocations; 2219 mLocations.clear(); 2220 2221 // The ID map list will be repopulated automatically by this loop 2222 mIDMapMounts.clear(); 2223 2227 2224 for(std::vector<std::string>::iterator 2228 2225 pLocName = locNames.begin(); … … 2230 2227 pLocName++) 2231 2228 { 2229 Location* pLoc = NULL; 2230 2231 // Try to find and reuse an existing Location object 2232 for(Locations::const_iterator 2233 i = tmpLocations.begin(); 2234 i != tmpLocations.end(); i++) 2235 { 2236 if ((*i)->mName == *pLocName) 2237 { 2238 BOX_TRACE("Location already configured: " << *pLocName); 2239 pLoc = *i; 2240 break; 2241 } 2242 } 2243 2232 2244 const Configuration& rConfig( 2233 2245 rLocationsConf.GetSubConfiguration(*pLocName)); 2234 BOX_TRACE("new location: " << *pLocName); 2235 2236 // Create a record for it 2237 std::auto_ptr<Location> apLoc(new Location); 2246 std::auto_ptr<Location> apLoc; 2238 2247 2239 2248 try 2240 2249 { 2241 // Setup names in the location record 2242 apLoc->mName = *pLocName; 2243 apLoc->mPath = rConfig.GetKeyValue("Path"); 2244 2245 // Read the exclude lists from the Configuration 2246 apLoc->mpExcludeFiles = BackupClientMakeExcludeList_Files(rConfig); 2247 apLoc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(rConfig); 2250 if(pLoc == NULL) 2251 { 2252 // Create a record for it 2253 BOX_TRACE("New location: " << *pLocName); 2254 pLoc = new Location; 2255 2256 // ensure deletion if setup fails 2257 apLoc.reset(pLoc); 2258 2259 // Setup names in the location record 2260 pLoc->mName = *pLocName; 2261 pLoc->mPath = rConfig.GetKeyValue("Path"); 2262 2263 // Read the exclude lists from the Configuration 2264 pLoc->mpExcludeFiles = BackupClientMakeExcludeList_Files(rConfig); 2265 pLoc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(rConfig); 2266 } 2248 2267 2249 2268 // Does this exist on the server? … … 2252 2271 // consider to remote one for deletion. 2253 2272 BackupStoreDirectory::Iterator iter(dir); 2254 BackupStoreFilenameClear dirname( apLoc->mName); // generate the filename2273 BackupStoreFilenameClear dirname(pLoc->mName); // generate the filename 2255 2274 BackupStoreDirectory::Entry *en = iter.FindMatchingClearName(dirname); 2256 2275 int64_t oid = 0; … … 2272 2291 #ifdef HAVE_STRUCT_STATVFS_F_MNTONNAME 2273 2292 struct statvfs s; 2274 if(::statvfs( apLoc->mPath.c_str(), &s) != 0)2293 if(::statvfs(pLoc->mPath.c_str(), &s) != 0) 2275 2294 #else // HAVE_STRUCT_STATVFS_F_MNTONNAME 2276 2295 struct statfs s; 2277 if(::statfs( apLoc->mPath.c_str(), &s) != 0)2296 if(::statfs(pLoc->mPath.c_str(), &s) != 0) 2278 2297 #endif // HAVE_STRUCT_STATVFS_F_MNTONNAME 2279 2298 { 2280 BOX_LOG_SYS_WARNING("Failed to stat location " 2281 "path '" << apLoc->mPath << 2282 "', skipping location '" << 2283 apLoc->mName << "'"); 2284 continue; 2299 BOX_THROW_SYS_ERROR("Failed to stat " 2300 "path '" << pLoc->mPath << 2301 "' for location '" << 2302 pLoc->mName << "'"); 2285 2303 } 2286 2304 … … 2291 2309 2292 2310 // Warn in logs if the directory isn't absolute 2293 if( apLoc->mPath[0] != '/')2311 if(pLoc->mPath[0] != '/') 2294 2312 { 2295 2313 BOX_WARNING("Location path '" 2296 << apLoc->mPath2314 << pLoc->mPath 2297 2315 << "' is not absolute"); 2298 2316 } … … 2309 2327 // (sorting order ensures this) 2310 2328 BOX_TRACE("checking against mount point " << *i); 2311 if(::strncmp(i->c_str(), apLoc->mPath.c_str(), i->size()) == 0)2329 if(::strncmp(i->c_str(), pLoc->mPath.c_str(), i->size()) == 0) 2312 2330 { 2313 2331 // Match … … 2317 2335 } 2318 2336 BOX_TRACE("mount point chosen for " 2319 << apLoc->mPath << " is "2337 << pLoc->mPath << " is " 2320 2338 << mountName); 2321 2339 } … … 2328 2346 { 2329 2347 // Yes -- store the index 2330 apLoc->mIDMapIndex = f->second;2348 pLoc->mIDMapIndex = f->second; 2331 2349 } 2332 2350 else 2333 2351 { 2334 2352 // No -- new index 2335 apLoc->mIDMapIndex = numIDMaps;2353 pLoc->mIDMapIndex = numIDMaps; 2336 2354 mounts[mountName] = numIDMaps; 2337 2355 … … 2353 2371 try 2354 2372 { 2355 attr.ReadAttributes( apLoc->mPath.c_str(),2373 attr.ReadAttributes(pLoc->mPath.c_str(), 2356 2374 true /* directories have zero mod times */, 2357 2375 0 /* not interested in mod time */, … … 2361 2379 { 2362 2380 BOX_ERROR("Failed to get attributes " 2363 "for path '" << apLoc->mPath2381 "for path '" << pLoc->mPath 2364 2382 << "', skipping location '" << 2365 apLoc->mName << "'");2366 continue;2383 pLoc->mName << "'"); 2384 throw; 2367 2385 } 2368 2386 … … 2382 2400 { 2383 2401 BOX_ERROR("Failed to create remote " 2384 "directory '/" << apLoc->mName <<2402 "directory '/" << pLoc->mName << 2385 2403 "', skipping location '" << 2386 apLoc->mName << "'");2387 continue;2404 pLoc->mName << "'"); 2405 throw; 2388 2406 } 2389 2407 … … 2392 2410 // Create and store the directory object for the root of this location 2393 2411 ASSERT(oid != 0); 2394 BackupClientDirectoryRecord *precord = 2395 new BackupClientDirectoryRecord(oid, *pLocName); 2396 apLoc->mpDirectoryRecord.reset(precord); 2412 if(pLoc->mpDirectoryRecord.get() == NULL) 2413 { 2414 BackupClientDirectoryRecord *precord = 2415 new BackupClientDirectoryRecord(oid, *pLocName); 2416 pLoc->mpDirectoryRecord.reset(precord); 2417 } 2397 2418 2419 // Remove it from the temporary list to avoid deletion 2420 tmpLocations.remove(pLoc); 2421 2398 2422 // Push it back on the vector of locations 2399 mLocations.push_back(apLoc.release()); 2423 mLocations.push_back(pLoc); 2424 2425 if(apLoc.get() != NULL) 2426 { 2427 // Don't delete it now! 2428 apLoc.release(); 2429 } 2400 2430 } 2401 2431 catch (std::exception &e) 2402 2432 { 2403 2433 BOX_ERROR("Failed to configure location '" 2404 << apLoc->mName << "' path '"2405 << apLoc->mPath << "': " << e.what() <<2434 << pLoc->mName << "' path '" 2435 << pLoc->mPath << "': " << e.what() << 2406 2436 ": please check for previous errors"); 2407 throw;2437 mReadErrorsOnFilesystemObjects = true; 2408 2438 } 2409 2439 catch(...) 2410 2440 { 2411 2441 BOX_ERROR("Failed to configure location '" 2412 << apLoc->mName << "' path '"2413 << apLoc->mPath << "': please check for "2442 << pLoc->mName << "' path '" 2443 << pLoc->mPath << "': please check for " 2414 2444 "previous errors"); 2415 throw; 2416 } 2417 } 2445 mReadErrorsOnFilesystemObjects = true; 2446 } 2447 } 2448 2449 // Now remove any leftovers 2450 for(BackupDaemon::Locations::iterator 2451 i = tmpLocations.begin(); 2452 i != tmpLocations.end(); i++) 2453 { 2454 BOX_INFO("Removing obsolete location from memory: " << 2455 (*i)->mName); 2456 delete *i; 2457 } 2458 2459 tmpLocations.clear(); 2418 2460 2419 2461 // Any entries in the root directory which need deleting? … … 2689 2731 { 2690 2732 // Search for the location 2691 for( std::vector<Location *>::const_iterator i(mLocations.begin()); i != mLocations.end(); ++i)2733 for(Locations::const_iterator i(mLocations.begin()); i != mLocations.end(); ++i) 2692 2734 { 2693 2735 if((*i)->mName == rLocationName) … … 3051 3093 anArchive.Write(iCount); 3052 3094 3053 for(int v = 0; v < iCount; v++) 3054 { 3055 ASSERT(mLocations[v]); 3056 mLocations[v]->Serialize(anArchive); 3095 for(Locations::const_iterator i = mLocations.begin(); 3096 i != mLocations.end(); i++) 3097 { 3098 ASSERT(*i); 3099 (*i)->Serialize(anArchive); 3057 3100 } 3058 3101 -
box/trunk/bin/bbackupd/BackupDaemon.h
r2992 r3081 158 158 159 159 public: 160 typedef const std::vector<Location *> Locations;160 typedef std::list<Location *> Locations; 161 161 Locations GetLocations() { return mLocations; } 162 162 … … 164 164 int mState; // what the daemon is currently doing 165 165 166 std::vector<Location *>mLocations;166 Locations mLocations; 167 167 168 168 std::vector<std::string> mIDMapMounts;
Note: See TracChangeset
for help on using the changeset viewer.
