summaryrefslogtreecommitdiff
path: root/Echolot
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2002-07-03 00:33:40 +0000
committerPeter Palfrader <peter@palfrader.org>2002-07-03 00:33:40 +0000
commit04f38d78e593cd0387e3eaa5e6456551299d6cc5 (patch)
treec934f811b6678d5bee84922b0cc52d9f60d7c2ac /Echolot
parentb82fbcfe34876b74bb577f7cee193dd2a5877e78 (diff)
Handle empty metafiles
Diffstat (limited to 'Echolot')
-rw-r--r--Echolot/Storage/File.pm51
1 files changed, 31 insertions, 20 deletions
diff --git a/Echolot/Storage/File.pm b/Echolot/Storage/File.pm
index 8e03bb1..ac8fe08 100644
--- a/Echolot/Storage/File.pm
+++ b/Echolot/Storage/File.pm
@@ -1,7 +1,7 @@
package Echolot::Storage::File;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: File.pm,v 1.17 2002/07/02 17:36:20 weasel Exp $
+# $Id: File.pm,v 1.18 2002/07/03 00:33:40 weasel Exp $
#
=pod
@@ -59,6 +59,8 @@ sub new {
my $self = {};
bless $self, $class;
+ $self->{'METADATA_FILE_IS_NEW'} = 0;
+
defined($params{'datadir'}) or
confess ('No datadir option passed to new');
$self->{'datadir'} = $params{'datadir'};
@@ -124,6 +126,7 @@ sub metadata_open($) {
cluck("Cannot open $filename for reading: $!"),
return 0;
} else {
+ $self->{'METADATA_FILE_IS_NEW'} = 1;
open($self->{'METADATA_FH'}, '+>' . $filename) or
cluck("Cannot open $filename for reading: $!"),
return 0;
@@ -148,27 +151,35 @@ sub metadata_close($) {
sub metadata_read($) {
my ($self) = @_;
- $self->{'METADATA'} = ();
- seek($self->{'METADATA_FH'}, 0, SEEK_SET) or
- cluck("Cannot seek to start of metadata file: $!"),
- return 0;
- eval {
- my $parser = new XML::Parser(Style => 'Tree');
- my $tree = $parser->parse( $self->{'METADATA_FH'} );
- my $dump = new XML::Dumper;
- $self->{'METADATA'} = $dump->xml2pl($tree);
- };
- $EVAL_ERROR and
- cluck("Error when reading from metadata file: $EVAL_ERROR"),
- return 0;
+ if ($self->{'METADATA_FILE_IS_NEW'}) {
+ $self->{'METADATA'}->{'version'} = $METADATA_VERSION;
+ $self->{'METADATA'}->{'addresses'} = ();
+ $self->{'METADATA'}->{'remailers'} = ();
- defined($self->{'METADATA'}->{'version'}) or
- cluck("Stored data lacks version header"),
- return 0;
- ($self->{'METADATA'}->{'version'} == ($METADATA_VERSION)) or
- cluck("Metadata version mismatch ($self->{'METADATA'}->{'version'} vs. $METADATA_VERSION)"),
- return 0;
+ $self->{'METADATA_FILE_IS_NEW'} = 0;
+ $self->commit();
+ } else {
+ $self->{'METADATA'} = ();
+ seek($self->{'METADATA_FH'}, 0, SEEK_SET) or
+ cluck("Cannot seek to start of metadata file: $!"),
+ return 0;
+ eval {
+ my $parser = new XML::Parser(Style => 'Tree');
+ my $tree = $parser->parse( $self->{'METADATA_FH'} );
+ my $dump = new XML::Dumper;
+ $self->{'METADATA'} = $dump->xml2pl($tree);
+ };
+ $EVAL_ERROR and
+ cluck("Error when reading from metadata file: $EVAL_ERROR"),
+ return 0;
+ defined($self->{'METADATA'}->{'version'}) or
+ cluck("Stored data lacks version header"),
+ return 0;
+ ($self->{'METADATA'}->{'version'} == ($METADATA_VERSION)) or
+ cluck("Metadata version mismatch ($self->{'METADATA'}->{'version'} vs. $METADATA_VERSION)"),
+ return 0;
+ };
defined($self->{'METADATA'}->{'secret'}) or
$self->{'METADATA'}->{'secret'} = Echolot::Tools::make_random ( 16, armor => 1 ),