--- deliantra/Deliantra/Deliantra.pm 2006/02/23 05:46:34 1.27 +++ deliantra/Deliantra/Deliantra.pm 2006/02/23 13:15:22 1.28 @@ -47,6 +47,26 @@ sub MOVE_SWIM (){ 0x8 } sub MOVE_ALL (){ 0xf } +sub load_ref($) { + my ($path) = @_; + + open my $fh, ">:raw", "$path~" + or die "$path~: $!"; + local $/; + Storable::thaw <$fh> +} + +sub save_ref($$) { + my ($ref, $path) = @_; + + open my $fh, ">:raw", "$path~" + or die "$path~: $!"; + print $fh Storable::nfreeze $ref; + close $fh; + rename "$path~", $path + or die "$path: $!"; +} + sub normalize_arch($) { my ($ob) = @_; @@ -115,9 +135,8 @@ eval { defined $cache - && -e $cache && -M $cache < -M $path - && Storable::retrieve ($cache) + && load_ref $cache } or do { my %pak; @@ -129,7 +148,7 @@ read $fh, $pak{$path}, $len; } - Storable::nstore (\%pak, $cache) + save_ref \%pak, $cache if defined $cache; \%pak @@ -141,9 +160,8 @@ eval { defined $cache - && -e $cache && -M $cache < -M $path - && Storable::retrieve ($cache) + && load_ref $cache } or do { my %arc; my ($more, $prev); @@ -208,7 +226,7 @@ undef $parse_block; # work around bug in perl not freeing $fh etc. - Storable::nstore (\%arc, $cache) + save_ref \%arc, $cache if defined $cache; \%arc