Added global option --root to operate on a different directory
authorMartin Vidner <mvidner@suse.cz>
Thu, 1 Feb 2007 13:32:57 +0000 (13:32 +0000)
committerMartin Vidner <mvidner@suse.cz>
Thu, 1 Feb 2007 13:32:57 +0000 (13:32 +0000)
(#238165, F#301963).

doc/zypper.8
package/zypper.changes
src/zmart-misc.cc
src/zmart-sources.cc
src/zmart.h
src/zypper.cc

index 6eb3b59..a51940c 100644 (file)
@@ -242,6 +242,9 @@ Specifies table style to use. Table style is identified by an integer number. TO
 .TP
 .I \-r, \-\-rug\-compatible
 Turns on rug compatibility. See compatibility notes next to affected commands.
+.TP
+.I \-R, \-\-root <dir>
+Operates on a different root directory.
 
 .SH "FILES"
 .TP
index ada1556..57911ae 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Thu Feb  1 14:25:29 CET 2007 - mvidner@suse.cz
+
+- Added global option --root to operate on a different directory
+  (#238165, F#301963).
+
+-------------------------------------------------------------------
 Wed Jan 31 16:19:38 CET 2007 - jkupec@suse.cz
 
 - locale support added (merged from 10.2/SP1 branch)
index c290cc2..f5be025 100644 (file)
@@ -24,10 +24,10 @@ void cond_init_target () {
   if (!done) {
 #ifdef LIBZYPP_1xx
     cerr_v << _("Initializing Target") << _(" (old way)") << endl;
-    God->initTarget("/", true);
+    God->initTarget(gSettings.root_dir, true);
 #else
     cerr_v << _("Initializing Target") << endl;
-    God->initializeTarget("/");
+    God->initializeTarget(gSettings.root_dir);
 #endif
     done = true;
   }
index 675f795..06f6a1c 100644 (file)
@@ -46,7 +46,7 @@ void init_system_sources()
   try
   {
     cerr << _("Restoring system sources...") << endl;
-    manager->restore("/");
+    manager->restore(gSettings.root_dir);
   }
 //  catch (const SourcesAlreadyRestoredException& excpt) {
 //  }
@@ -151,10 +151,10 @@ void list_system_sources()
   try
   {
 #ifdef LIBZYPP_1xx
-    sources = SourceManager::sourceManager()->knownSourceInfos ("/");
+    sources = SourceManager::sourceManager()->knownSourceInfos (gSettings.root_dir);
 #else
     zypp::storage::PersistentStorage store;
-    store.init( "/" );
+    store.init( gSettings.root_dir );
     sources = store.storedSources();
 #endif
   }
@@ -233,7 +233,7 @@ void add_source_by_url( const zypp::Url &url, const string &alias,
   cerr_vv << "Constructing SourceManager" << endl;
   SourceManager_Ptr manager = SourceManager::sourceManager();
   cerr_vv << "Restoring SourceManager" << endl;
-  manager->restore ("/", true /*use_cache*/);
+  manager->restore (gSettings.root_dir, true /*use_cache*/);
 
   list<SourceManager::SourceId> sourceIds;
 
@@ -276,7 +276,7 @@ void add_source_by_url( const zypp::Url &url, const string &alias,
     }
 
     cerr_vv << "Storing source data" << endl;
-    manager->store( "/", true /*metadata_cache*/ );
+    manager->store( gSettings.root_dir, true /*metadata_cache*/ );
 }
 
 template<typename T>
@@ -320,7 +320,7 @@ void remove_source( const std::string& anystring )
   SourceManager_Ptr manager = SourceManager::sourceManager();
   cerr_vv << "Restoring SourceManager" << endl;
   try {
-    manager->restore ("/", true /*use_cache*/);
+    manager->restore (gSettings.root_dir, true /*use_cache*/);
     }
   catch (const Exception & ex) {
     // so what if sources cannot be restored
@@ -383,7 +383,7 @@ void remove_source( const std::string& anystring )
   }
 
   cerr_vv << "Storing source data" << endl;
-  manager->store( "/", true /*metadata_cache*/ );
+  manager->store( gSettings.root_dir, true /*metadata_cache*/ );
 }
 
 //! rename a source, identified in any way: alias, url, id
@@ -396,7 +396,7 @@ void rename_source( const std::string& anystring, const std::string& newalias )
   cerr_vv << "Constructing SourceManager" << endl;
   SourceManager_Ptr manager = SourceManager::sourceManager();
   cerr_vv << "Restoring SourceManager" << endl;
-  manager->restore ("/", true /*use_cache*/);
+  manager->restore (gSettings.root_dir, true /*use_cache*/);
 
   Source_Ref src;
 
@@ -454,7 +454,7 @@ void rename_source( const std::string& anystring, const std::string& newalias )
   }
 
   cerr_vv << "Storing source data" << endl;
-  manager->store( "/", true /*metadata_cache*/ );
+  manager->store( gSettings.root_dir, true /*metadata_cache*/ );
 #endif
 }
 
@@ -468,7 +468,7 @@ void refresh_sources()
 
   try
   {
-    store.init( "/" );
+    store.init( gSettings.root_dir );
     sources = store.storedSources();
   }
   catch ( const Exception &e )
index 73163eb..2e7024f 100644 (file)
@@ -51,7 +51,8 @@ struct Settings
   previous_code(-1),
   disable_system_sources(false),
   disable_system_resolvables(false),
-  is_rug_compatible(false)
+  is_rug_compatible(false),
+  root_dir("/")
   {}
 
   std::list<zypp::Url> additional_sources;
@@ -62,6 +63,7 @@ struct Settings
   bool disable_system_sources;
   bool disable_system_resolvables;
   bool is_rug_compatible;
+  std::string root_dir;
 };
 
 struct Error
@@ -105,4 +107,7 @@ extern std::ostream no_stream;
 // define new _ macro
 #define _(MSG) ::gettext(MSG)
 
+// Local Variables:
+// c-basic-offset: 2
+// End:
 #endif
index 3a29c8e..d084df7 100644 (file)
@@ -53,6 +53,7 @@ static struct option global_options[] = {
   {"terse",    no_argument, 0, 't'},
   {"table-style", required_argument, 0, 's'},
   {"rug-compatible", no_argument, 0, 'r'},
+  {"root",     required_argument, 0, 'R'},
   {"opt",      optional_argument, 0, 'o'},
   {0, 0, 0, 0}
 };
@@ -123,7 +124,8 @@ string process_globals(int argc, char **argv)
     "\t--verbose, -v\t\tIncrease verbosity\n"
     "\t--terse, -t\t\tTerse output for machine consumption\n"
     "\t--table-style, -s\tTable style (integer)\n"
-    "\t--rug-compatible, -r\tTurn on rug compatibility\n");
+    "\t--rug-compatible, -r\tTurn on rug compatibility\n"
+    "\t--root, -R <dir>\tOperate on a different root directory\n");
     ;
 
   if (gopts.count("verbose")) {
@@ -139,6 +141,12 @@ string process_globals(int argc, char **argv)
     else
       cerr << _("Invalid table style ") << s << endl;
   }
+
+  if (gopts.count("root")) {
+    gSettings.root_dir = gopts["root"].front();
+  }
+
+
   // testing option
   if (gopts.count("opt")) {
     cerr << "Opt arg: ";