Changeset 1872


Ignore:
Timestamp:
17/10/2007 13:44:49 (4 years ago)
Author:
chris
Message:

Don't abort if one of the location paths doesn't exist, just print a
warning
and continue.

Use an auto_ptr to avoid memory leaks when setting up a location fails.

(merges [1828])

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupd/BackupDaemon.cpp

    r1863 r1872  
    16651665                BOX_TRACE("new location: " << i->first); 
    16661666                // Create a record for it 
    1667                 Location *ploc = new Location; 
     1667                std::auto_ptr<Location> apLoc(new Location); 
     1668 
    16681669                try 
    16691670                { 
    16701671                        // Setup names in the location record 
    1671                         ploc->mName = i->first; 
    1672                         ploc->mPath = i->second.GetKeyValue("Path"); 
     1672                        apLoc->mName = i->first; 
     1673                        apLoc->mPath = i->second.GetKeyValue("Path"); 
    16731674                         
    16741675                        // Read the exclude lists from the Configuration 
    1675                         ploc->mpExcludeFiles = BackupClientMakeExcludeList_Files(i->second); 
    1676                         ploc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(i->second); 
     1676                        apLoc->mpExcludeFiles = BackupClientMakeExcludeList_Files(i->second); 
     1677                        apLoc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(i->second); 
     1678 
    16771679                        // Does this exist on the server? 
    16781680                        // Remove from dir object early, so that if we fail 
     
    16801682                        // consider to remote one for deletion. 
    16811683                        BackupStoreDirectory::Iterator iter(dir); 
    1682                         BackupStoreFilenameClear dirname(ploc->mName);  // generate the filename 
     1684                        BackupStoreFilenameClear dirname(apLoc->mName); // generate the filename 
    16831685                        BackupStoreDirectory::Entry *en = iter.FindMatchingClearName(dirname); 
    16841686                        int64_t oid = 0; 
     
    17001702#ifdef HAVE_STRUCT_STATVFS_F_MNTONNAME 
    17011703                                struct statvfs s; 
    1702                                 if(::statvfs(ploc->mPath.c_str(), &s) != 0) 
     1704                                if(::statvfs(apLoc->mPath.c_str(), &s) != 0) 
    17031705#else // HAVE_STRUCT_STATVFS_F_MNTONNAME 
    17041706                                struct statfs s; 
    1705                                 if(::statfs(ploc->mPath.c_str(), &s) != 0) 
     1707                                if(::statfs(apLoc->mPath.c_str(), &s) != 0) 
    17061708#endif // HAVE_STRUCT_STATVFS_F_MNTONNAME 
    17071709                                { 
    1708                                         BOX_WARNING("Failed to stat location: " 
    1709                                                 << ploc->mPath  
    1710                                                 << ": " << strerror(errno)); 
    1711                                         THROW_EXCEPTION(CommonException, 
    1712                                                 OSFileError) 
     1710                                        BOX_WARNING("Failed to stat location " 
     1711                                                "path '" << apLoc->mPath << 
     1712                                                "' (" << strerror(errno) << 
     1713                                                "), skipping location '" << 
     1714                                                apLoc->mName << "'"); 
     1715                                        continue; 
    17131716                                } 
    17141717 
     
    17191722 
    17201723                                // Warn in logs if the directory isn't absolute 
    1721                                 if(ploc->mPath[0] != '/') 
     1724                                if(apLoc->mPath[0] != '/') 
    17221725                                { 
    17231726                                        BOX_WARNING("Location path '" 
    1724                                                 << ploc->mPath  
     1727                                                << apLoc->mPath  
    17251728                                                << "' is not absolute"); 
    17261729                                } 
     
    17371740                                                // (sorting order ensures this) 
    17381741                                                BOX_TRACE("checking against mount point " << *i); 
    1739                                                 if(::strncmp(i->c_str(), ploc->mPath.c_str(), i->size()) == 0) 
     1742                                                if(::strncmp(i->c_str(), apLoc->mPath.c_str(), i->size()) == 0) 
    17401743                                                { 
    17411744                                                        // Match 
     
    17451748                                        } 
    17461749                                        BOX_TRACE("mount point chosen for " 
    1747                                                 << ploc->mPath << " is " 
     1750                                                << apLoc->mPath << " is " 
    17481751                                                << mountName); 
    17491752                                } 
     
    17561759                                { 
    17571760                                        // Yes -- store the index 
    1758                                         ploc->mIDMapIndex = f->second; 
     1761                                        apLoc->mIDMapIndex = f->second; 
    17591762                                } 
    17601763                                else 
    17611764                                { 
    17621765                                        // No -- new index 
    1763                                         ploc->mIDMapIndex = numIDMaps; 
     1766                                        apLoc->mIDMapIndex = numIDMaps; 
    17641767                                        mounts[mountName] = numIDMaps; 
    17651768                                         
     
    17811784                                try 
    17821785                                { 
    1783                                         attr.ReadAttributes(ploc->mPath.c_str(),  
     1786                                        attr.ReadAttributes(apLoc->mPath.c_str(),  
    17841787                                                true /* directories have zero mod times */, 
    17851788                                                0 /* not interested in mod time */,  
     
    17891792                                { 
    17901793                                        BOX_ERROR("Failed to get attributes " 
    1791                                                 "for path '" << ploc->mPath 
    1792                                                 << "', skipping."); 
     1794                                                "for path '" << apLoc->mPath 
     1795                                                << "', skipping location '" << 
     1796                                                apLoc->mName << "'"); 
    17931797                                        continue; 
    17941798                                } 
     
    17981802                                { 
    17991803                                        MemBlockStream attrStream(attr); 
    1800                                         std::auto_ptr<BackupProtocolClientSuccess> dirCreate(connection.QueryCreateDirectory( 
     1804                                        std::auto_ptr<BackupProtocolClientSuccess> 
     1805                                                dirCreate(connection.QueryCreateDirectory( 
    18011806                                                BackupProtocolClientListDirectory::RootDirectory, 
    18021807                                                attrModTime, dirname, attrStream)); 
     
    18081813                                { 
    18091814                                        BOX_ERROR("Failed to create remote " 
    1810                                                 "directory '/" << ploc->mName << 
    1811                                                 "', skipping location."); 
     1815                                                "directory '/" << apLoc->mName << 
     1816                                                "', skipping location '" << 
     1817                                                apLoc->mName << "'"); 
    18121818                                        continue; 
    18131819                                } 
     
    18181824                        ASSERT(oid != 0); 
    18191825                        BackupClientDirectoryRecord *precord = new BackupClientDirectoryRecord(oid, i->first); 
    1820                         ploc->mpDirectoryRecord.reset(precord); 
     1826                        apLoc->mpDirectoryRecord.reset(precord); 
    18211827                         
    18221828                        // Push it back on the vector of locations 
    1823                         mLocations.push_back(ploc); 
     1829                        mLocations.push_back(apLoc.release()); 
    18241830                } 
    18251831                catch (std::exception &e) 
    18261832                { 
    18271833                        BOX_ERROR("Failed to configure location '" 
    1828                                 << ploc->mName << "' path '" 
    1829                                 << ploc->mPath << "': " << e.what() << 
     1834                                << apLoc->mName << "' path '" 
     1835                                << apLoc->mPath << "': " << e.what() << 
    18301836                                ": please check for previous errors"); 
    1831                         delete ploc; 
    1832                         ploc = 0; 
    18331837                        throw; 
    18341838                } 
     
    18361840                { 
    18371841                        BOX_ERROR("Failed to configure location '" 
    1838                                 << ploc->mName << "' path '" 
    1839                                 << ploc->mPath << "': please check for " 
     1842                                << apLoc->mName << "' path '" 
     1843                                << apLoc->mPath << "': please check for " 
    18401844                                "previous errors"); 
    1841  
    1842                         delete ploc; 
    1843                         ploc = NULL; 
    1844  
    18451845                        throw; 
    18461846                } 
Note: See TracChangeset for help on using the changeset viewer.