Author: jkupec Date: Fri Aug 10 14:40:15 2007 New Revision: 6578 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6578&view=rev Log: - Fix restoring of Sources if root prefix is used. (#238165) Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/SourceManager.cc branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/SourceManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/SourceManager.cc?rev=6578&r1=6577&r2=6578&view=diff ============================================================================== --- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/SourceManager.cc (original) +++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/SourceManager.cc Fri Aug 10 14:40:15 2007 @@ -185,7 +185,7 @@ void SourceManager::renameSource( SourceId id, const std::string & new_alias_r ) { Source_Ref src = findSource(id); - + if ( src ) { // delete the old entry in the storage @@ -195,9 +195,9 @@ // set the new alias src.setAlias( new_alias_r ); } - + } - + void SourceManager::removeSource(SourceManager::SourceId id) { if ( ! sourceTableRemove( _sources.find(id) ) ) @@ -316,7 +316,7 @@ } _renamed_sources.clear(); - + // delete before modifying and creating // so that we can recreate a deleted one (#174295) for ( SourceMap::iterator it = _deleted_sources.begin(); it != _deleted_sources.end(); it++) @@ -339,7 +339,17 @@ descr.setType( it->second.type() ); descr.setPath( it->second.path() ); - descr.setCacheDir( it->second.cacheDir() ); + // WATCH OUT! + // Source::cacheDir contains the root prefix. + // Strip it from SourceInfo::CacheDir! + if ( root_r.empty() || root_r == "/" ) + { + descr.setCacheDir( it->second.cacheDir() ); + } + else + { + descr.setCacheDir( str::stripPrefix( it->second.cacheDir().asString(), root_r.asString() ) ); + } if ( metadata_cache && descr.cacheDir().empty() ) { @@ -431,13 +441,19 @@ } // Note: Url(it->url).asString() to hide password in logs - MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl; + MIL << "Restoring source: url:[" << it->url().asString() + << "] product_dir:[" << it->path() + << "] alias:[" << it->alias() + << "] cache_dir:[" << it->cacheDir() + << "] auto_refresh:[ " << it->autorefresh() << "]" << endl; SourceId id = 0; try { - Source_Ref src = SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir(), false, it->autorefresh()); + Source_Ref src = SourceFactory().createFrom( it->type(), it->url(), it->path(), it->alias(), + root_r / it->cacheDir(), + false, it->autorefresh() ); id = addSource(src); } catch (const Exception &expt ) @@ -457,7 +473,9 @@ url2.setQueryParam("devices", ""); DBG << "CD/DVD devices changed - try again without a devices list" << std::endl; - id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir(), false ) ); + id = addSource( SourceFactory().createFrom( url2, it->path(), it->alias(), + root_r / it->cacheDir(), + false ) ); // This worked ... update it->url ? //it->url = url2.asCompleteString(); Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h?rev=6578&r1=6577&r2=6578&view=diff ============================================================================== --- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h (original) +++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h Fri Aug 10 14:40:15 2007 @@ -311,6 +311,20 @@ std::string getline( std::istream & str, const Trim trim_r ); + /////////////////////////////////////////////////////////////////// + + /** \name String prefix handling. + */ + //@{ + /** Return whether \a str_r has prefix \a prefix_r. */ + inline bool hasPrefix( const std::string & str_r, const std::string & prefix_r ) + { return( str_r.substr( 0, prefix_r.size() ) == prefix_r ); } + + /** Strip a \a prefix_r from \a str_r and return the resulting string. */ + inline std::string stripPrefix( const std::string & str_r, const std::string & prefix_r ) + { return( hasPrefix( str_r, prefix_r ) ? str_r.substr( prefix_r.size() ) : str_r ); } + //@} + ///////////////////////////////////////////////////////////////// } // namespace str /////////////////////////////////////////////////////////////////// -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org