diff options
-rw-r--r-- | NPTest.pm | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -422,6 +422,7 @@ sub LoadCache | |||
422 | { | 422 | { |
423 | return if exists( $CACHE{'_cache_loaded_'} ); | 423 | return if exists( $CACHE{'_cache_loaded_'} ); |
424 | 424 | ||
425 | my $fileContents = ""; | ||
425 | if ( -f $CACHEFILENAME ) | 426 | if ( -f $CACHEFILENAME ) |
426 | { | 427 | { |
427 | my( $fileHandle ) = new IO::File; | 428 | my( $fileHandle ) = new IO::File; |
@@ -432,44 +433,45 @@ sub LoadCache | |||
432 | return; | 433 | return; |
433 | } | 434 | } |
434 | 435 | ||
435 | my( $fileContents ) = join( "\n", <$fileHandle> ); | 436 | $fileContents = join("", <$fileHandle>); |
436 | |||
437 | $fileHandle->close(); | 437 | $fileHandle->close(); |
438 | 438 | ||
439 | chomp($fileContents); | ||
439 | my( $contentsRef ) = eval $fileContents; | 440 | my( $contentsRef ) = eval $fileContents; |
440 | %CACHE = %{$contentsRef}; | 441 | %CACHE = %{$contentsRef}; |
441 | 442 | ||
442 | } | 443 | } |
443 | 444 | ||
444 | $CACHE{'_cache_loaded_'} = 1; | 445 | $CACHE{'_cache_loaded_'} = 1; |
446 | $CACHE{'_original_cache'} = $fileContents; | ||
445 | } | 447 | } |
446 | 448 | ||
447 | 449 | ||
448 | sub SaveCache | 450 | sub SaveCache |
449 | { | 451 | { |
450 | delete $CACHE{'_cache_loaded_'}; | 452 | delete $CACHE{'_cache_loaded_'}; |
453 | my $oldFileContents = delete $CACHE{'_original_cache'}; | ||
451 | 454 | ||
452 | my( $fileHandle ) = new IO::File; | 455 | my($dataDumper) = new Data::Dumper([\%CACHE]); |
453 | |||
454 | if ( ! $fileHandle->open( "> ${CACHEFILENAME}" ) ) | ||
455 | { | ||
456 | print STDERR "NPTest::LoadCache() : Problem saving ${CACHEFILENAME} : $!\n"; | ||
457 | return; | ||
458 | } | ||
459 | |||
460 | my( $dataDumper ) = new Data::Dumper( [ \%CACHE ] ); | ||
461 | |||
462 | $dataDumper->Terse(1); | 456 | $dataDumper->Terse(1); |
463 | $dataDumper->Sortkeys(1); | 457 | $dataDumper->Sortkeys(1); |
464 | |||
465 | my $data = $dataDumper->Dump(); | 458 | my $data = $dataDumper->Dump(); |
466 | $data =~ s/^\s+/ /gmx; # make sure all systems use same amount of whitespace | 459 | $data =~ s/^\s+/ /gmx; # make sure all systems use same amount of whitespace |
467 | $data =~ s/^\s+}/}/gmx; | 460 | $data =~ s/^\s+}/}/gmx; |
468 | print $fileHandle $data; | 461 | chomp($data); |
469 | 462 | ||
470 | $fileHandle->close(); | 463 | if($oldFileContents ne $data) { |
464 | my($fileHandle) = new IO::File; | ||
465 | if (!$fileHandle->open( "> ${CACHEFILENAME}")) { | ||
466 | print STDERR "NPTest::LoadCache() : Problem saving ${CACHEFILENAME} : $!\n"; | ||
467 | return; | ||
468 | } | ||
469 | print $fileHandle $data; | ||
470 | $fileHandle->close(); | ||
471 | } | ||
471 | 472 | ||
472 | $CACHE{'_cache_loaded_'} = 1; | 473 | $CACHE{'_cache_loaded_'} = 1; |
474 | $CACHE{'_original_cache'} = $data; | ||
473 | } | 475 | } |
474 | 476 | ||
475 | # | 477 | # |