diff options
| author | fukachan <fukachan> | 2004-05-25 04:03:06 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2004-05-25 04:03:06 +0000 |
| commit | 2ade973949b05deb4d692b6c8e4bf5c45e94a930 (patch) | |
| tree | c70cc2595efd812c374be0cde783259080fecca7 /fml/lib/IO/Adapter/File.pm | |
| parent | c9c6067d4efb56b1f9a1c5b54b39826cce09cdd4 (diff) | |
| download | fml8-2ade973949b05deb4d692b6c8e4bf5c45e94a930.tar.gz fml8-2ade973949b05deb4d692b6c8e4bf5c45e94a930.tar.bz2 fml8-2ade973949b05deb4d692b6c8e4bf5c45e94a930.zip | |
more strict write error tracking.
sequence_increment verifies if the value is writtern.
Diffstat (limited to 'fml/lib/IO/Adapter/File.pm')
| -rw-r--r-- | fml/lib/IO/Adapter/File.pm | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm index 8a246a08..96a7a407 100644 --- a/fml/lib/IO/Adapter/File.pm +++ b/fml/lib/IO/Adapter/File.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: File.pm,v 1.54 2004/04/10 07:40:02 fukachan Exp $ +# $FML: File.pm,v 1.55 2004/04/11 12:58:39 fukachan Exp $ # package IO::Adapter::File; @@ -636,6 +636,11 @@ sub sequence_increment use IO::Adapter::AtomicFile; my ($rh, $wh) = IO::Adapter::AtomicFile->rw_open($file); + if ($rh->error || $wh->error) { + $self->error_set("fail to open temporary files."); + return 0; + } + # read the current sequence number if (defined $rh) { $id = $self->_read_one_word($rh); @@ -657,13 +662,36 @@ sub sequence_increment # save $id if (defined $wh) { + $wh->autoflush(1); + $wh->clearerr(); print $wh $id, "\n"; - $wh->close; + if ($wh->error()) { + $self->error_set("write error"); + $wh->rollback(); + return 0; + } + else { + $wh->close; + } } else { $self->error_set("cannot save id"); } + # verify if the value is writtern. + { + use IO::Adapter::AtomicFile; + my ($rh, $wh) = IO::Adapter::AtomicFile->rw_open($file); + if (defined $rh) { + my $new_id = $self->_read_one_word($rh); + unless ($new_id == $id) { + $self->error_set("fail to save id"); + return 0; + } + $rh->close(); + } + } + return $id; } @@ -686,8 +714,15 @@ sub sequence_replace # save $id if (defined $wh) { + $wh->clearerr(); print $wh $new_id, "\n"; - $wh->close; + if ($wh->error()) { + $self->error_set("write error"); + $wh->rollback(); + } + else { + $wh->close; + } } else { $self->error_set("cannot save id"); |
