Subject: | Support for db->verify |
Hi there,
I just went through a woody->sarge upgrade, which went remarkably well except for old databases scattered around the filesystem, especially spamassassin and movabletype.
It would be nice for these programs to upgrade out-of-date databases, but they do need a mechanism to do so.
Here is a patch which appears to offer the possibility of doing a database upgrade, with BerkeleyDB::db_upgrade.
My first time playing with .xs :-)
Gary.
diff -ru libberkeleydb-perl-0.26/BerkeleyDB.pm libberkeleydb-perl-0.26-new/BerkeleyDB.pm
--- libberkeleydb-perl-0.26/BerkeleyDB.pm 2004-10-10 21:25:14.000000000 +0100
+++ libberkeleydb-perl-0.26-new/BerkeleyDB.pm 2005-06-21 19:06:55.000000000 +0100
@@ -623,6 +623,24 @@
return _db_verify($got);
}
+sub db_upgrade
+{
+ my $got = BerkeleyDB::ParseParameters(
+ {
+ Filename => undef,
+ Flags => 0,
+ Env => undef,
+ }, @_) ;
+
+ croak("Env not of type BerkeleyDB::Env")
+ if defined $got->{Env} and ! isa($got->{Env},'BerkeleyDB::Env');
+
+ croak("Must specify a filename")
+ if ! defined $got->{Filename} ;
+
+ return _db_upgrade($got);
+}
+
package BerkeleyDB::Env ;
use UNIVERSAL qw( isa ) ;
diff -ru libberkeleydb-perl-0.26/BerkeleyDB.pod libberkeleydb-perl-0.26-new/BerkeleyDB.pod
--- libberkeleydb-perl-0.26/BerkeleyDB.pod 2004-10-10 21:35:54.000000000 +0100
+++ libberkeleydb-perl-0.26-new/BerkeleyDB.pod 2005-06-21 19:34:16.000000000 +0100
@@ -25,6 +25,7 @@
$status = BerkeleyDB::db_remove [OPTIONS]
$status = BerkeleyDB::db_rename [OPTIONS]
$status = BerkeleyDB::db_verify [OPTIONS]
+ $status = BerkeleyDB::db_upgrade [OPTIONS]
$hash{$key} = $value ;
$value = $hash{$key} ;
@@ -409,6 +410,7 @@
$status = BerkeleyDB::db_remove [OPTIONS]
$status = BerkeleyDB::db_rename [OPTIONS]
$status = BerkeleyDB::db_verify [OPTIONS]
+ $status = BerkeleyDB::db_upgrade [OPTIONS]
=head1 THE DATABASE CLASSES
diff -ru libberkeleydb-perl-0.26/BerkeleyDB.xs libberkeleydb-perl-0.26-new/BerkeleyDB.xs
--- libberkeleydb-perl-0.26/BerkeleyDB.xs 2004-10-10 21:25:29.000000000 +0100
+++ libberkeleydb-perl-0.26-new/BerkeleyDB.xs 2005-06-21 19:44:38.000000000 +0100
@@ -1565,6 +1565,38 @@
RETVAL
DualType
+_db_upgrade(ref)
+ SV * ref
+ CODE:
+ {
+#ifndef AT_LEAST_DB_3_1
+ softCrash("BerkeleyDB::db_upgrade needs Berkeley DB 3.1.x or better") ;
+#else
+ HV * hash ;
+ DB * dbp ;
+ SV * sv ;
+ const char * db = NULL ;
+ BerkeleyDB__Env env = NULL ;
+ DB_ENV * dbenv = NULL ;
+ u_int32_t flags = 0 ;
+
+ hash = (HV*) SvRV(ref) ;
+ SetValue_pv(db, "Filename", char *) ;
+ SetValue_iv(flags, "Flags") ;
+ SetValue_ov(env, "Env", BerkeleyDB__Env) ;
+ RETVAL = 0;
+ if (env)
+ dbenv = env->Env ;
+ RETVAL = db_create(&dbp, dbenv, 0) ;
+ if (RETVAL == 0) {
+ RETVAL = dbp->upgrade(dbp, db, flags) ;
+ }
+#endif
+ }
+ OUTPUT:
+ RETVAL
+
+DualType
_db_rename(ref)
SV * ref
CODE: