[Groonga-commit] ranguba/rroonga at 2e095ed [master] Add Groonga::Database#remove_force to bind grn_obj_remove_force()

Back to archive index

Masafumi Yokoyama null+****@clear*****
Fri Oct 7 15:04:05 JST 2016


Masafumi Yokoyama	2016-10-07 15:04:05 +0900 (Fri, 07 Oct 2016)

  New Revision: 2e095eda6d3dda334ad0cac91426bbf86cf316eb
  https://github.com/ranguba/rroonga/commit/2e095eda6d3dda334ad0cac91426bbf86cf316eb

  Merged 06d1190: Merge pull request #134 from ranguba/bind-grn-obj-remove-force

  Message:
    Add Groonga::Database#remove_force to bind grn_obj_remove_force()
    
    GitHub: #131

  Modified files:
    ext/groonga/rb-grn-database.c
    test/test-database.rb

  Modified: ext/groonga/rb-grn-database.c (+33 -0)
===================================================================
--- ext/groonga/rb-grn-database.c    2016-10-06 17:27:15 +0900 (2fd70d7)
+++ ext/groonga/rb-grn-database.c    2016-10-07 15:04:05 +0900 (750a50b)
@@ -705,6 +705,38 @@ rb_grn_database_reindex (VALUE self)
     return Qnil;
 }
 
+/*
+ * Removes a broken object.
+ *
+ * You should use {Groonga::Object#remove} normally.
+ *
+ * @overload remove_force(name)
+ *
+ *   @param [String] name The target object name.
+ *
+ * @since 6.0.9
+ */
+static VALUE
+rb_grn_database_remove_force (VALUE self, VALUE rb_name)
+{
+    grn_rc rc;
+    grn_ctx *context;
+    char *name;
+    int name_size;
+
+    rb_grn_database_deconstruct(SELF(self), NULL, &context,
+                                NULL, NULL, NULL, NULL);
+
+    name = StringValueCStr(rb_name);
+    name_size = RSTRING_LEN(rb_name);
+
+    rc = grn_obj_remove_force(context, name, name_size);
+    rb_grn_context_check(context, self);
+    rb_grn_rc_check(rc, self);
+
+    return Qnil;
+}
+
 void
 rb_grn_init_database (VALUE mGrn)
 {
@@ -740,4 +772,5 @@ rb_grn_init_database (VALUE mGrn)
     rb_define_method(rb_cGrnDatabase, "recover", rb_grn_database_recover, 0);
     rb_define_method(rb_cGrnDatabase, "unmap", rb_grn_database_unmap, 0);
     rb_define_method(rb_cGrnDatabase, "reindex", rb_grn_database_reindex, 0);
+    rb_define_method(rb_cGrnDatabase, "remove_force", rb_grn_database_remove_force, 1);
 }

  Modified: test/test-database.rb (+21 -0)
===================================================================
--- test/test-database.rb    2016-10-06 17:27:15 +0900 (715ad8d)
+++ test/test-database.rb    2016-10-07 15:04:05 +0900 (c5e6609)
@@ -276,6 +276,27 @@ class DatabaseTest < Test::Unit::TestCase
                  terms.collect(&:_key).sort)
   end
 
+  def test_remove_force
+    setup_database
+    table_name = "Bookmarks"
+    table = Groonga::Array.create(:name => table_name)
+    table_path = Pathname.new(table.path)
+    @database.unmap
+    table_path.open("w") do |file|
+      file.print("BROKEN")
+    end
+    assert_raise(Groonga::IncompatibleFileFormat) do
+      context[table_name]
+    end
+    assert do
+      table_path.exist?
+    end
+    @database.remove_force(table_name)
+    assert do
+      not table_path.exist?
+    end
+  end
+
   class RemoveTest < self
     setup :setup_database
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index