diff options
author | Stig Thormodsrud <stig@vyatta.com> | 2009-04-27 14:40:25 -0700 |
---|---|---|
committer | Stig Thormodsrud <stig@vyatta.com> | 2009-04-27 14:40:25 -0700 |
commit | 927622c3aa679293c7a380a4c7c5d129067c5c8a (patch) | |
tree | e69b22f4668488b6665f6ca83d54d4c95c787a7e | |
parent | ad8e4618e5a517b22ef5180ad59b0c116e0aaaa1 (diff) | |
download | vyatta-cfg-quagga-927622c3aa679293c7a380a4c7c5d129067c5c8a.tar.gz vyatta-cfg-quagga-927622c3aa679293c7a380a4c7c5d129067c5c8a.zip |
Avoid unnecessary writing of file if it's the same contents.
-rw-r--r-- | scripts/vyatta-banner.pl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/vyatta-banner.pl b/scripts/vyatta-banner.pl index e1cd70a1..8c3db846 100644 --- a/scripts/vyatta-banner.pl +++ b/scripts/vyatta-banner.pl @@ -33,6 +33,8 @@ use Vyatta::Config; use Getopt::Long; use File::Copy; +use Digest::MD5 qw(md5_hex); +use Digest::file qw(digest_file_hex); use strict; use warnings; @@ -55,9 +57,23 @@ sub restore_orig_file { return; } +sub is_same_as_file { + my ($file, $value) = @_; + + return if ! -e $file; + my $fdigest = digest_file_hex($file, "MD5"); + my $vdigest = md5_hex("$value"); + return 1 if $fdigest eq $vdigest; + return; +} + sub write_file_value { my ($file, $value) = @_; + # Avoid unnecessary writes. At boot the file will be the + # regenerated with the same content. + return if is_same_as_file($file, $value); + open my $F, '>', $file or die "Error: opening $file [$!]"; print $F "$value"; close $F; |