<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -23,6 +23,8 @@
           not being supported (Edo and Tokyo)
 - added : can set built-in or custom comparison functions for b-tree databases
           (Edo interface only)
+- todo  : reenabled #copy for Tyrant (Edo and Tokyo)
+
 
 == rufus-tokyo - 1.0.1    released 2009/09/18
 </diff>
      <filename>CHANGELOG.txt</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,7 @@
 [o] implement q.metasearch(q, u)
 [o] table/delete_keys_with_prefix, use searchout
 [o] default value / default_proc for cabinets
+[o] self.open for tables
 
 [ ] ldelete for tables ?
 
@@ -32,5 +33,5 @@
 
 [ ] wire setmutex for Cabinet (and ?)
 
-[ ] self.open for tables
+[ ] copy for tyrant tables ?
 </diff>
      <filename>TODO.txt</filename>
    </modified>
    <modified>
      <diff>@@ -119,14 +119,18 @@ module Rufus::Edo
       self.stat['size']
     end
 
-    # isn't that a bit dangerous ? it creates a file on the server...
+    # Tells the Tyrant server to create a copy of itself at the given (remote)
+    # target_path.
     #
-    # DISABLED.
+    # Returns true when successful.
+    #
+    # Note : if you started your ttserver with a path like &quot;tyrants/data.tch&quot;
+    # you have to provide a target path in the same subdir, like
+    # &quot;tyrants/data_prime.tch&quot;.
     #
     def copy (target_path)
 
-      #@db.copy(target_path)
-      raise 'not allowed to create files on the server'
+      @db.copy(target_path) || raise_error
     end
 
     # Copies the current cabinet to a new file.</diff>
      <filename>lib/rufus/edo/ntyrant/abstract.rb</filename>
    </modified>
    <modified>
      <diff>@@ -123,20 +123,25 @@ module Rufus::Tokyo
       TyrantLib
     end
 
-    # isn't that a bit dangerous ? it creates a file on the server...
+    # Tells the Tyrant server to create a copy of itself at the given (remote)
+    # target_path.
     #
-    # DISABLED.
+    # Returns true when successful.
+    #
+    # Note : if you started your ttserver with a path like &quot;tyrants/data.tch&quot;
+    # you have to provide a target path in the same subdir, like
+    # &quot;tyrants/data_prime.tch&quot;.
     #
     def copy (target_path)
 
-      #@db.copy(target_path)
-      raise 'not allowed to create files on the server'
+      (lib.abs_copy(@db, target_path) == 1) || raise_error
     end
 
     # Tyrant databases DO NOT support the 'defrag' call. Calling this method
     # will raise an exception.
     #
     def defrag
+
       raise(NoMethodError.new(&quot;Tyrant dbs don't support #defrag&quot;))
     end
 
@@ -154,6 +159,13 @@ module Rufus::Tokyo
 
       lib.tcrdbstat(@db)
     end
+
+    def raise_error
+
+      code = lib.abs_ecode(@db)
+      message = lib.abs_errmsg(@db, code)
+      raise TokyoError.new(&quot;(err #{code}) #{message}&quot;)
+    end
   end
 end
 </diff>
      <filename>lib/rufus/tokyo/tyrant/abstract.rb</filename>
    </modified>
    <modified>
      <diff>@@ -64,6 +64,9 @@ module Rufus::Tokyo
     attfunc :tcrdbopen, [ :pointer, :string, :int ], :int
     attfunc :abs_close, :tcrdbclose, [ :pointer ], :int
 
+    attfunc :abs_ecode, :tcrdbecode, [ :pointer ], :int
+    attfunc :abs_errmsg, :tcrdberrmsg, [ :pointer, :int ], :string
+
     attfunc :abs_del, :tcrdbdel, [ :pointer ], :void
 
     attfunc :abs_rnum, :tcrdbrnum, [ :pointer ], :uint64
@@ -110,7 +113,7 @@ module Rufus::Tokyo
     attfunc :tab_out, :tcrdbtblout, [ :pointer, :string, :int ], :int
 
     attfunc :tab_ecode, :tcrdbecode, [ :pointer ], :int
-    attfunc :tab_errmsg, :tcrdberrmsg, [ :int ], :string
+    attfunc :tab_errmsg, :tcrdberrmsg, [ :pointer, :int ], :string
 
     attfunc :tab_del, :tcrdbdel, [ :pointer ], :void
 </diff>
      <filename>lib/rufus/tokyo/tyrant/lib.rb</filename>
    </modified>
    <modified>
      <diff>@@ -103,6 +103,7 @@ if defined?(Rufus::Edo)
     end
 
     behaves_like 'a Tyrant structure (no transactions)'
+    behaves_like 'a Tyrant structure (copy method)'
   end
 
   describe Rufus::Edo::NetTyrant do</diff>
      <filename>spec/edo_ntyrant_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,3 +22,21 @@ shared 'a Tyrant structure (no transactions)' do
   end
 end
 
+shared 'a Tyrant structure (copy method)' do
+
+  it 'should accept #copy calls' do
+
+    SOURCE = 'tmp/tyrant.tch'
+
+    TARGET = File.expand_path(
+      File.join(File.dirname(__FILE__), '../tmp/tyrant_copy.tch'))
+
+    @db.copy(TARGET)
+
+    File.exist?(TARGET).should.be.true
+    File.stat(TARGET).size.should.equal(File.stat(SOURCE).size)
+
+    FileUtils.rm(TARGET)
+  end
+end
+</diff>
      <filename>spec/shared_tyrant_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,7 @@ ttserver \
   -port 45000 \
   -pid $TMP/t_spec.pid -rts $TMP/t_spec.rts \
   -log $TMP/t.log \
+  -unmask copy \
   $TMP/tyrant.tch
 
 ttserver \</diff>
      <filename>spec/start_tyrants.sh</filename>
    </modified>
    <modified>
      <diff>@@ -90,6 +90,7 @@ describe Rufus::Tokyo::Tyrant do
 
   behaves_like 'an abstract structure'
   behaves_like 'a Tyrant structure (no transactions)'
+  behaves_like 'a Tyrant structure (copy method)'
 
   it 'should respond to stat' do
 </diff>
      <filename>spec/tyrant_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e44436fb7e2f0e2b39c4bc890e5d4854d33a15ea</id>
    </parent>
  </parents>
  <author>
    <name>John Mettraux</name>
    <email>jmettraux@gmail.com</email>
  </author>
  <url>http://github.com/jmettraux/rufus-tokyo/commit/3bbc937e508fee0757106db3130c53ef384679a2</url>
  <id>3bbc937e508fee0757106db3130c53ef384679a2</id>
  <committed-date>2009-10-13T07:55:58-07:00</committed-date>
  <authored-date>2009-10-13T07:55:04-07:00</authored-date>
  <message>todo : reenabled #copy for Tyrant (Edo and Tokyo) - closes gh-19

(would be good to have one at hand for tyrant tables)</message>
  <tree>284aae8bef3d734e1ee058d370359dd517f8205b</tree>
  <committer>
    <name>John Mettraux</name>
    <email>jmettraux@gmail.com</email>
  </committer>
</commit>
