zypper service-add -r http://example.org/foo.repo (F#300641).
authorMartin Vidner <mvidner@suse.cz>
Tue, 17 Oct 2006 17:18:06 +0000 (17:18 +0000)
committerMartin Vidner <mvidner@suse.cz>
Tue, 17 Oct 2006 17:18:06 +0000 (17:18 +0000)
package/libzypp.changes
tools/zmart/zmart-sources.cc
tools/zmart/zmart-sources.h
tools/zmart/zypper.cc

index 6d4afd6..6b62240 100644 (file)
@@ -1,4 +1,9 @@
 -------------------------------------------------------------------
+Tue Oct 17 19:17:39 CEST 2006 - mvidner@suse.cz
+
+- zypper service-add -r http://example.org/foo.repo (F#300641).
+
+-------------------------------------------------------------------
 Tue Oct 17 18:29:34 CEST 2006 - dmacvicar@suse.de
 
 - zypp-checkpatches:
index 3675a6a..557afa1 100644 (file)
@@ -257,6 +257,24 @@ void safe_lexical_cast (Source s, Target &tr) {
   }
 }
 
+static
+bool looks_like_url (const string& s) {
+  static bool schemes_shown = false;
+  if (!schemes_shown) {
+    cerr_vv << "Registered schemes: " << Url::getRegisteredSchemes () << endl;
+    schemes_shown = true;
+  }
+
+  string::size_type pos = s.find (':');
+  if (pos != string::npos) {
+    string scheme (s, 0, pos);
+    if (Url::isRegisteredScheme (scheme)) {
+      return true;
+    }
+  }
+  return false;
+}
+
 //! remove a source, identified in any way: alias, url, id
 // may throw:
 void remove_source( const std::string& anystring )
@@ -282,12 +300,7 @@ void remove_source( const std::string& anystring )
   }
   else {
     bool is_url = false;
-    // could it be a URL?
-    cerr_vv << "Registered schemes: " << Url::getRegisteredSchemes () << endl;
-    string::size_type pos = anystring.find (':');
-    if (pos != string::npos) {
-      string scheme (anystring, 0, pos);
-      if (Url::isRegisteredScheme (scheme)) {
+    if (looks_like_url (anystring)) {
        is_url = true;
        cerr_vv << "Looks like a URL" << endl;
 
@@ -309,7 +322,6 @@ void remove_source( const std::string& anystring )
          }
          manager->removeSourceByUrl (url);
        }
-      }
     }
 
     if (!is_url) {
@@ -352,12 +364,7 @@ void rename_source( const std::string& anystring, const std::string& newalias )
   }
   else {
     bool is_url = false;
-    // could it be a URL?
-    cerr_vv << "Registered schemes: " << Url::getRegisteredSchemes () << endl;
-    string::size_type pos = anystring.find (':');
-    if (pos != string::npos) {
-      string scheme (anystring, 0, pos);
-      if (Url::isRegisteredScheme (scheme)) {
+    if (looks_like_url (anystring)) {
        is_url = true;
        cerr_vv << "Looks like a URL" << endl;
 
@@ -378,7 +385,6 @@ void rename_source( const std::string& anystring, const std::string& newalias )
            cerr << format ("Source %s not found.") % url.asString() << endl;
          }
        }
-      }
     }
 
     if (!is_url) {
@@ -399,6 +405,37 @@ void rename_source( const std::string& anystring, const std::string& newalias )
   cerr_vv << "Storing source data" << endl;
   manager->store( "/", true /*metadata_cache*/ );
 }
+
+MediaWrapper::MediaWrapper (const string& filename_or_url) {
+  try {
+    // the interface cannot provide a "complete path" :-(
+    Url url (filename_or_url);
+    Pathname path (url.getPathName ());
+    url.setPathName ("/");
+
+    _id = _mm.open (url);
+    _mm.attach (_id);
+
+    _mm.provideFile (_id, path);
+    Pathname local = _mm.localPath (_id, path);
+    _local_path = local.asString ();
+  }
+  catch (const Exception & ex) {
+    ZYPP_CAUGHT (ex);
+    if (looks_like_url (filename_or_url)) {
+    cerr << "Error while fetching " << filename_or_url << " : "
+        << ex << endl;
+//      ex.dumpOn (cerr);              // this suxxz
+    }
+    _local_path = filename_or_url;
+  }
+}
+
+MediaWrapper::~MediaWrapper () {
+  if (_mm.isOpen (_id))
+    _mm.close (_id);
+}
+
 // Local Variables:
 // c-basic-offset: 2
 // End:
index c6efffe..6e3ab08 100644 (file)
@@ -22,5 +22,22 @@ void remove_source( const std::string& anystring );
 void rename_source( const std::string& anystring, const std::string& newalias );
 void list_system_sources();
 
+
+//! download a copy of a remote file or just return the argument
+// The file is deleted when this class is destroyed
+class MediaWrapper : private zypp::base::NonCopyable {
+public:
+  MediaWrapper (const std::string& filename_or_url);
+  ~MediaWrapper ();
+  std::string localPath () const {
+    return _local_path;
+  }
+
+private:
+  zypp::media::MediaManager _mm; // noncopyable
+  zypp::media::MediaId _id;  
+  std::string _local_path;
+};
+
 #endif
 
index 487bc2a..b743ad5 100644 (file)
@@ -281,6 +281,7 @@ int main(int argc, char **argv)
     specific_options = service_add_options;
     specific_help = "  Command options:\n"
       "\t--repo,-r <FILE.repo>\tRead the URL and alias from a file\n"
+      "\t\t\t\t(even remote)\n"
       ;
   }
   else if (command == "service-list" || command == "sl") {
@@ -452,7 +453,12 @@ int main(int argc, char **argv)
 
     string repoalias, repourl;
     if (copts.count("repo")) {
-      parse_repo_file (copts["repo"].front(), repourl, repoalias);
+      string filename = copts["repo"].front();
+      // it may be an URL; cache the file while MediaWrapper exists
+      MediaWrapper download (filename);
+      filename = download.localPath ();
+      cerr_vv << "Got: " << filename << endl;
+      parse_repo_file (filename, repourl, repoalias);
     }
 
     if (help || (arguments.size() < 1 && repoalias.empty ())) {