Recurisive directory unset



Hey Havoc,
	I missed Glynn's mails on this because I wasn't on this list
'til now ...

	Anyway I don't understand why you said "there's no mkdir/rmdir
operation". Unless, I'm mistaken that's what the remove_dir backend
vtable operation and gconf_engine_remove_dir is ?

	I've attached two patches:

	1) Add a --recursive-delete-dir option to gconftool and fix an
	assertion in the xml backend. (Could you comment on the two
	FIXMEs I added? )

	2) Remove calls to POA::activate_object, which are useless on
	the RootPOA, since the RootPOA supports implicit activation
	... and you were leaking ObjectIds anyway :-)

	May I commit ?

Good Luck,
Mark.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gconf/ChangeLog,v
retrieving revision 1.342
diff -u -p -r1.342 ChangeLog
--- ChangeLog	2002/01/05 20:21:33	1.342
+++ ChangeLog	2002/01/07 08:38:25
@@ -1,3 +1,10 @@
+2002-01-07  Mark McLoughlin  <mark skynet ie>
+
+	* gconf/gconftool.c: (main): add --recursive-delete-dir option.
+	(recursive_delete_dir_helper), (do_recursive_delete_dir): impl.
+
+	* backends/xml-dir.c: (dir_sync): fix incorrect assertion.
+
 2002-01-05  Havoc Pennington  <hp pobox com>

 	* gconf/gconf-client.c (gconf_client_cache): return bool for
Index: backends/xml-dir.c
===================================================================
RCS file: /cvs/gnome/gconf/backends/xml-dir.c,v
retrieving revision 1.23
diff -u -p -r1.23 xml-dir.c
--- backends/xml-dir.c	2001/12/11 20:26:28	1.23
+++ backends/xml-dir.c	2002/01/07 08:38:25
@@ -69,7 +69,7 @@ struct _Dir {
   GTime last_access; /* so we know when to un-cache */
   xmlDocPtr doc;
   GHashTable* entry_cache; /* store key-value entries */
-  GHashTable* subdir_cache; /* store subdirectories */
+  GHashTable* subdir_cache; /* store subdirectories : FIMXE: not used? */
   guint dir_mode;
   guint file_mode;
   guint dirty : 1;
@@ -286,13 +286,15 @@ dir_sync        (Dir* d, GError** err)
   if (!d->dirty)
     return TRUE;

-  /* We should have a doc if dirty is TRUE */
-  g_assert(d->doc != NULL);
-
   d->last_access = time(NULL);

   if (d->deleted)
     {
+      /*
+       * FIXME: should we recursively sync all subdirs here to be
+       *        sure any deleted subdirs get deleted first?
+       */
+
       if (unlink(d->xml_filename) != 0)
         {
           gconf_set_error(err, GCONF_ERROR_FAILED, _("Failed to delete `%s': %s"),
@@ -313,6 +315,9 @@ dir_sync        (Dir* d, GError** err)
       gchar* tmp_filename;
       gchar* old_filename;
       FILE* outfile;
+
+      /* We should have a doc if deleted is FALSE */
+      g_assert(d->doc != NULL);

       /* First make sure entry values are synced to their
          XML nodes */
Index: gconf/gconftool.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconftool.c,v
retrieving revision 1.67
diff -u -p -r1.67 gconftool.c
--- gconf/gconftool.c	2002/01/03 20:50:53	1.67
+++ gconf/gconftool.c	2002/01/07 08:38:25
@@ -59,6 +59,7 @@ static int schema_name_mode = FALSE;
 static int associate_schema_mode = FALSE;
 static int default_source_mode = FALSE;
 static int recursive_unset_mode = FALSE;
+static int recursive_delete_dir_mode = FALSE;

 struct poptOption options[] = {
   {
@@ -116,6 +117,15 @@ struct poptOption options[] = {
     N_("Recursively unset all keys at or below the key/directory names on the command line"),
     NULL
   },
+  {
+    "recursive-delete-dir",
+    '\0',
+    POPT_ARG_NONE,
+    &recursive_delete_dir_mode,
+    0,
+    N_("Recursively delete all directories on the command line"),
+    NULL
+  },
   {
     "all-entries",
     'a',
@@ -366,6 +376,7 @@ static int do_set_schema(GConfEngine* co
 static int do_all_entries(GConfEngine* conf, const gchar** args);
 static int do_unset(GConfEngine* conf, const gchar** args);
 static int do_recursive_unset (GConfEngine* conf, const gchar** args);
+static int do_recursive_delete_dir (GConfEngine* conf, const gchar** args);
 static int do_all_subdirs(GConfEngine* conf, const gchar** args);
 static int do_load_schema_file(GConfEngine* conf, const gchar* file);
 static int do_short_docs (GConfEngine *conf, const gchar **args);
@@ -529,6 +540,7 @@ main (int argc, char** argv)
     }

   /* FIXME not checking that --recursive-unset is used alone */
+  /* FIXME not checking that --recursive-delete-dir is used alone */

   if (use_local_source && config_source == NULL)
     {
@@ -793,6 +805,17 @@ main (int argc, char** argv)
         }
     }

+  if (recursive_delete_dir_mode)
+    {
+      const gchar** args = poptGetArgs(ctx);
+
+      if (do_recursive_delete_dir(conf, args) == 1)
+        {
+          gconf_engine_unref(conf);
+          return 1;
+        }
+    }
+
   if (all_subdirs_mode)
     {
       const gchar** args = poptGetArgs(ctx);
@@ -1676,7 +1699,106 @@ do_recursive_unset (GConfEngine* conf, c
   while (*args)
     {
       recursive_unset_helper (conf, *args);
+
+      ++args;
+    }
+
+  return 0;
+}
+
+static void
+recursive_delete_dir_helper (GConfEngine *conf,
+			     const char  *dir)
+{
+  GError* err = NULL;
+  GSList* subdirs;
+  GSList* entries;
+  GSList* tmp;
+
+  if (!gconf_engine_dir_exists (conf, dir, &err))
+    {
+      if (err == NULL)
+	{
+	  fprintf (stderr, _("Directory '%s' does not exist\n"), dir);
+	}
+      else
+	{
+          fprintf (stderr, _("Error querying directory '%s': %s\n"),
+                   dir, err->message);
+          g_error_free (err);
+          err = NULL;
+	}
+
+      return;
+    }
+
+  subdirs = gconf_engine_all_dirs (conf, dir, &err);
+
+  if (subdirs != NULL)
+    {
+      tmp = subdirs;
+
+      while (tmp != NULL)
+        {
+          gchar* s = tmp->data;
+
+          recursive_delete_dir_helper (conf, s);
+
+          g_free (s);
+
+          tmp = g_slist_next (tmp);
+        }
+
+      g_slist_free (subdirs);
+    }
+  else
+    {
+      if (err != NULL)
+        {
+          fprintf (stderr, _("Error listing subdirs of '%s': %s\n"),
+                   dir, err->message);
+          g_error_free(err);
+          err = NULL;
+        }
+    }
+
+   gconf_engine_remove_dir (conf, dir, &err);
+   if (err != NULL)
+     {
+	fprintf (stderr, _("Error deleting directory '%s' : %s\n"),
+		 dir, err->message);
+	g_error_free (err);
+	err = NULL;
+     }
+
+  /*
+   * We have to do this now, because we must
+   * ensure that directories are deleted in order.
+   */
+  gconf_engine_suggest_sync (conf, &err);
+  if (err != NULL)
+    {
+      fprintf (stderr, _("Error syncing : '%s'\n"), err->message);
+      g_error_free (err);
+      err = NULL;
+    }
+}
+
+static int
+do_recursive_delete_dir (GConfEngine* conf, const gchar** args)
+{
+  GError *err = NULL;
+
+  if (args == NULL)
+    {
+      fprintf (stderr, _("Must specify one or more directories to delete.\n"));
+      return 1;
+    }

+  while (*args)
+    {
+      recursive_delete_dir_helper (conf, *args);
+
       ++args;
     }


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gconf/ChangeLog,v
retrieving revision 1.342
diff -u -p -r1.342 ChangeLog
--- ChangeLog	2002/01/05 20:21:33	1.342
+++ ChangeLog	2002/01/07 08:44:50
@@ -1,3 +1,10 @@
+2002-01-07  Mark McLoughlin  <mark skynet ie>
+
+	* gconf/gconf-database.c: (gconf_database_new):
+	* gconf/gconf.c: (gconf_get_config_listener):
+	* gconf/gconfd.c: (main): no need to explicitly activate CORBA objects,
+	the RootPOA has the IMPLICIT_ACTIVATION policy.
+
 2002-01-05  Havoc Pennington  <hp pobox com>

 	* gconf/gconf-client.c (gconf_client_cache): return bool for
Index: gconf/gconf-database.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf-database.c,v
retrieving revision 1.26
diff -u -p -r1.26 gconf-database.c
--- gconf/gconf-database.c	2002/01/04 17:52:33	1.26
+++ gconf/gconf-database.c	2002/01/07 08:44:50
@@ -789,7 +789,6 @@ gconf_database_new (GConfSources  *sourc
 {
   GConfDatabase* db;
   CORBA_Environment ev;
-  PortableServer_ObjectId* objid;

   db = g_new0 (GConfDatabase, 1);

@@ -800,11 +799,6 @@ gconf_database_new (GConfSources  *sourc

   POA_ConfigDatabase3__init (&db->servant, &ev);

-  objid =
-    PortableServer_POA_activate_object (gconf_get_poa (),
-                                        &db->servant,
-                                        &ev);
-
   db->objref = PortableServer_POA_servant_to_reference (gconf_get_poa (),
                                                         &db->servant,
                                                         &ev);
@@ -815,8 +809,6 @@ gconf_database_new (GConfSources  *sourc

       exit (1);
     }
-
-  CORBA_free (objid);

   db->listeners = gconf_listeners_new();

Index: gconf/gconf.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf.c,v
retrieving revision 1.127
diff -u -p -r1.127 gconf.c
--- gconf/gconf.c	2002/01/04 17:52:33	1.127
+++ gconf/gconf.c	2002/01/07 08:44:50
@@ -2202,7 +2202,6 @@ gconf_get_config_listener(void)
   if (listener == CORBA_OBJECT_NIL)
     {
       CORBA_Environment ev;
-      PortableServer_ObjectId* objid;
       PortableServer_POA poa;

       CORBA_exception_init (&ev);
@@ -2220,10 +2219,6 @@ gconf_get_config_listener(void)

       g_assert (ev._major == CORBA_NO_EXCEPTION);

-      objid = PortableServer_POA_activate_object (poa, &poa_listener_servant, &ev);
-
-      g_assert (ev._major == CORBA_NO_EXCEPTION);
-
       listener = PortableServer_POA_servant_to_reference(poa,
                                                          &poa_listener_servant,
                                                          &ev);
Index: gconf/gconfd.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconfd.c,v
retrieving revision 1.115
diff -u -p -r1.115 gconfd.c
--- gconf/gconfd.c	2002/01/04 17:52:33	1.115
+++ gconf/gconfd.c	2002/01/07 08:44:50
@@ -460,7 +460,6 @@ main(int argc, char** argv)
 {
   struct sigaction act;
   sigset_t empty_mask;
-  PortableServer_ObjectId* objid;
   CORBA_Environment ev;
   CORBA_ORB orb;
   gchar* logname;
@@ -563,8 +562,6 @@ main(int argc, char** argv)
   the_poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, "RootPOA", &ev);
   PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(the_poa, &ev), &ev);

-  objid = PortableServer_POA_activate_object(the_poa, &poa_server_servant, &ev);
-
   server = PortableServer_POA_servant_to_reference(the_poa,
                                                    &poa_server_servant,
                                                    &ev);





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]