Commit 5e5715df authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 301392: Storable crashes checksetup with byte order error when moving…

Bug 301392: Storable crashes checksetup with byte order error when moving databases - Patch by Dennis Melentyev <dennis.melentyev@infopulse.com.ua> r=mkanat a=justdave
parent 882d0395
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
# Edward J. Sabol <edwardjsabol@iname.com> # Edward J. Sabol <edwardjsabol@iname.com>
# Max Kanat-Alexander <mkanat@bugzilla.org> # Max Kanat-Alexander <mkanat@bugzilla.org>
# Lance Larsh <lance.larsh@oracle.com> # Lance Larsh <lance.larsh@oracle.com>
# Dennis Melentyev <dennis.melentyev@infopulse.com.ua>
package Bugzilla::DB::Schema; package Bugzilla::DB::Schema;
...@@ -36,8 +37,13 @@ use strict; ...@@ -36,8 +37,13 @@ use strict;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Util; use Bugzilla::Util;
use Safe;
# Historical, needed for SCHEMA_VERSION = '1.00'
use Storable qw(dclone freeze thaw); use Storable qw(dclone freeze thaw);
# New SCHEMA_VERSION (2.00) use this
use Data::Dumper;
=head1 NAME =head1 NAME
Bugzilla::DB::Schema - Abstract database schema for Bugzilla Bugzilla::DB::Schema - Abstract database schema for Bugzilla
...@@ -142,7 +148,7 @@ which can be used to specify the type of index such as UNIQUE or FULLTEXT. ...@@ -142,7 +148,7 @@ which can be used to specify the type of index such as UNIQUE or FULLTEXT.
=cut =cut
use constant SCHEMA_VERSION => '1.00'; use constant SCHEMA_VERSION => '2.00';
use constant ABSTRACT_SCHEMA => { use constant ABSTRACT_SCHEMA => {
# BUG-RELATED TABLES # BUG-RELATED TABLES
...@@ -1976,18 +1982,24 @@ sub columns_equal { ...@@ -1976,18 +1982,24 @@ sub columns_equal {
Do not attempt to manipulate this data directly, Do not attempt to manipulate this data directly,
as the format may change at any time in the future. as the format may change at any time in the future.
The only thing you should do with the returned value The only thing you should do with the returned value
is either store it somewhere or deserialize it. is either store it somewhere (coupled with appropriate
SCHEMA_VERSION) or deserialize it.
=cut =cut
sub serialize_abstract { sub serialize_abstract {
my ($self) = @_; my ($self) = @_;
# We do this so that any two stored Schemas will have the
# same byte representation if they are identical. # Make it ok to eval
# We don't need it currently, but it might make things local $Data::Dumper::Purity = 1;
# easier in the future.
local $Storable::canonical = 1; # Avoid cross-refs
return freeze($self->{abstract_schema}); local $Data::Dumper::Deepcopy = 1;
# Always sort keys to allow textual compare
local $Data::Dumper::Sortkeys = 1;
return Dumper($self->{abstract_schema});
} }
=item C<deserialize_abstract($serialized, $version)> =item C<deserialize_abstract($serialized, $version)>
...@@ -2007,12 +2019,16 @@ sub serialize_abstract { ...@@ -2007,12 +2019,16 @@ sub serialize_abstract {
sub deserialize_abstract { sub deserialize_abstract {
my ($class, $serialized, $version) = @_; my ($class, $serialized, $version) = @_;
my $thawed_hash = thaw($serialized); my $thawed_hash;
if (int($version) < 2) {
# At this point, we have no backwards-compatibility $thawed_hash = thaw($serialized);
# code to write, so $version is ignored. }
# For what $version ought to be used for, see the else {
# "private" section of the SCHEMA_VERSION docs. my $cpt = new Safe;
$cpt->reval($serialized) ||
die "Unable to restore cached schema: " . $@;
$thawed_hash = ${$cpt->varglob('VAR1')};
}
return $class->new(undef, $thawed_hash); return $class->new(undef, $thawed_hash);
} }
...@@ -2043,7 +2059,7 @@ object. ...@@ -2043,7 +2059,7 @@ object.
sub get_empty_schema { sub get_empty_schema {
my ($class) = @_; my ($class) = @_;
return $class->deserialize_abstract(freeze({})); return $class->deserialize_abstract(Dumper({}), SCHEMA_VERSION);
} }
1; 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment