}
}
+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 )
}
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;
}
manager->removeSourceByUrl (url);
}
- }
}
if (!is_url) {
}
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;
cerr << format ("Source %s not found.") % url.asString() << endl;
}
}
- }
}
if (!is_url) {
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:
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
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") {
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 ())) {