- allow / in aliases (#292628)
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 18 Jul 2007 12:17:48 +0000 (12:17 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 18 Jul 2007 12:17:48 +0000 (12:17 +0000)
package/libzypp.changes
tests/zypp/RepoManager_test.cc
zypp/RepoManager.cc

index b239a9d..6e85143 100644 (file)
@@ -7,6 +7,11 @@ Wed Jul 18 12:38:55 CEST 2007 - ma@suse.de
 - revision 6058
 
 -------------------------------------------------------------------
+Wed Jul 18 14:16:59 CEST 2007 - duncan@suse.de
+
+- allow / in alias (#292628) 
+
+-------------------------------------------------------------------
 Tue Jul 17 15:57:03 CEST 2007 - ma@suse.de
 
 - Fixed OnMediLocation to use safe defaults. Added setLocaltion and
index 381bc99..6bd750d 100644 (file)
@@ -62,6 +62,10 @@ void repomanager_test( const string &dir )
   repos = manager.knownRepositories();
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
   
+  RepoInfo office_dup;
+  office_dup.setAlias("office");
+  BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException);
+
   // delete the office repo inside the propietary_1.repo
   RepoInfo office;
   office.setAlias("office");
index 3dad1ec..e59c046 100644 (file)
@@ -682,6 +682,33 @@ namespace zypp
 
   ////////////////////////////////////////////////////////////////////////////
 
+  /**
+   * \short Generate a related filename from a repo info
+   *
+   * From a repo info, it will try to use the alias as a filename
+   * escaping it if necessary. Other fallbacks can be added to
+   * this function in case there is no way to use the alias
+   */
+  static std::string generate_filename( const RepoInfo &info )
+  {
+    std::string fnd="/";
+    std::string rep="_";
+    std::string filename = info.alias();
+    // replace slashes with underscores
+    size_t pos = filename.find(fnd);
+    while(pos!=string::npos)
+    {
+      filename.replace(pos,fnd.length(),rep);
+      pos = filename.find(fnd,pos+rep.length());
+    }
+    filename = Pathname(filename).extend(".repo").asString();
+    MIL << "generating filename for repo [" << info.alias() << "] : '" << filename << "'" << endl;
+    return filename;
+  }
+
+
+  ////////////////////////////////////////////////////////////////////////////
+
   void RepoManager::addRepository( const RepoInfo &info,
                                    const ProgressData::ReceiverFnc & progressrcv )
   {
@@ -708,7 +735,7 @@ namespace zypp
     filesystem::assert_dir(_pimpl->options.knownReposPath);
     
     Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath,
-                                                    Pathname(info.alias()).extend(".repo").asString());
+                                                    generate_filename(info));
     // now we have a filename that does not exists
     MIL << "Saving repo in " << repofile << endl;