[gvfs] Implement unset key in MetaTree



commit 14f92f57f36e5a5b245e747b5fe0840936137c3d
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Jun 22 16:16:34 2009 +0200

    Implement unset key in MetaTree

 metadata/metatree.c |   47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/metadata/metatree.c b/metadata/metatree.c
index c044b28..a950d6c 100644
--- a/metadata/metatree.c
+++ b/metadata/metatree.c
@@ -869,6 +869,19 @@ meta_journal_entry_new_setv (guint64 mtime,
   return meta_journal_entry_finish (out);
 }
 
+static GString *
+meta_journal_entry_new_unset (guint64 mtime,
+			      const char *path,
+			      const char *key)
+{
+  GString *out;
+
+  out = meta_journal_entry_init (JOURNAL_OP_UNSET_KEY, mtime, path);
+  append_string (out, key);
+  return meta_journal_entry_finish (out);
+}
+
+
 /* Call with writer lock held */
 static gboolean
 meta_journal_add_entry (MetaJournal *journal,
@@ -2140,8 +2153,38 @@ meta_tree_unset (MetaTree                         *tree,
 		 const char                       *path,
 		 const char                       *key)
 {
-  /* TODO */
-  return FALSE;
+  GString *entry;
+  guint64 mtime;
+  gboolean res;
+
+  g_static_rw_lock_writer_lock (&metatree_lock);
+
+  if (tree->journal == NULL ||
+      !tree->journal->journal_valid)
+    {
+      res = FALSE;
+      goto out;
+    }
+
+  mtime = time (NULL);
+
+  entry = meta_journal_entry_new_unset (mtime, path, key);
+
+  res = TRUE;
+ retry:
+  if (!meta_journal_add_entry (tree->journal, entry))
+    {
+      if (meta_tree_flush_locked (tree))
+	goto retry;
+
+      res = FALSE;
+    }
+
+  g_string_free (entry, TRUE);
+
+ out:
+  g_static_rw_lock_writer_unlock (&metatree_lock);
+  return res;
 }
 
 gboolean



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