diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2011-11-09 08:17:28 -0800 |
---|---|---|
committer | Stephen Hemminger <shemminger@vyatta.com> | 2011-11-09 08:17:28 -0800 |
commit | 02396d787f4f693622b3d0aef675473ff417a783 (patch) | |
tree | f23b3fc7c0bd874a58fb663b9e500dc042b5d265 /scripts | |
parent | 0e7340bf6b421b698578a908fa67ca6f629d698c (diff) | |
download | vyatta-op-02396d787f4f693622b3d0aef675473ff417a783.tar.gz vyatta-op-02396d787f4f693622b3d0aef675473ff417a783.zip |
cleanup rename-image
1. Get rid of perl critic warnings about use of bare file handles and open
2. Use perl rather than system() to copy and move files and check for errors.
3. Use perl rather than system() to access syslog.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rename-image.pl | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/scripts/rename-image.pl b/scripts/rename-image.pl index 8632334..be30967 100644 --- a/scripts/rename-image.pl +++ b/scripts/rename-image.pl @@ -24,6 +24,8 @@ use strict; use warnings; use Getopt::Long; use File::Temp qw/ tempfile tempdir /; +use File::Copy; +use Sys::Syslog qw/:standard :macros/; my $UNION_BOOT = '/live/image/boot'; my $XEN_DEFAULT_IMAGE = "$UNION_BOOT/%%default_image"; @@ -99,16 +101,14 @@ my $tmpfh; my $tmpfilename; ($tmpfh, $tmpfilename) = tempfile(); -if (!open (GRUBFH, "<${image_path}/grub/grub.cfg")) { - printf("Can't open grub file.\n"); - exit 1; -} +open (my $grubfh, '<', "${image_path}/grub/grub.cfg") + or die "Can't open grub file.\n"; # This is sensitive to the format of menu entries and boot paths # in the grub config file. # my $line; -while ($line = <GRUBFH>) { +while ($line = <$grubfh>) { $line =~ s/\/boot\/$old_name/\/boot\/$new_name/g; $line =~ s/Vyatta $old_name/Vyatta $new_name/; $line =~ s/Vyatta image $old_name/Vyatta image $new_name/; @@ -117,13 +117,14 @@ while ($line = <GRUBFH>) { } close($tmpfh); -close(GRUBFH); +close($grubfh); -system("mv $image_path/$old_name $image_path/$new_name"); -system("cp $tmpfilename $image_path/grub/grub.cfg"); +mv("$image_path/$old_name", "$image_path/$new_name") + or die "rename $old_name to $new_name failed: $!\n"; +cp($tmpfilename, "$image_path/grub/grub.cfg") + or die "copy $tmpfilename to grub.cfg failed: $!\n"; -system("logger -p local3.warning -t 'SystemImage' 'System image $old_name has been renamed $new_name'"); +syslog("warning", "System image $old_name has been renamed $new_name"); printf("Done.\n"); - |