From 58f8cf69b1797023c643170231611e661ab246ad Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 6 Dec 2010 15:45:38 -0800 Subject: Fix typo in export --- lib/Vyatta/Misc.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 949c6a2..a103c69 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -27,7 +27,7 @@ our @ISA = qw(Exporter); our @EXPORT = qw(getInterfaces getIP getNetAddIP get_sysfs_value is_address_enabled is_dhcp_enabled get_ipaddr_intf_hash isIpAddress is_ip_v4_or_v6 interface_description - is_local_addres); + is_local_address); our @EXPORT_OK = qw(generate_dhclient_intf_files getInterfacesIPadresses getPortRuleString); -- cgit v1.2.3 From 1044b3dd982e4d327ca1c3044bf70d12403a7f58 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 6 Dec 2010 16:26:10 -0800 Subject: Add some file common file routines Perl versions of commonly used backquote escapes. --- Makefile.am | 1 + lib/Vyatta/File.pm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 lib/Vyatta/File.pm (limited to 'lib') diff --git a/Makefile.am b/Makefile.am index 9daed20..bc4bb78 100644 --- a/Makefile.am +++ b/Makefile.am @@ -97,6 +97,7 @@ sbin_SCRIPTS += scripts/vyatta-check-typeless-node.pl sbin_SCRIPTS += scripts/vyatta-strip-migration-comments.pl share_perl5_DATA = lib/Vyatta/Config.pm +share_perl5_DATA += lib/Vyatta/File.pm share_perl5_DATA += lib/Vyatta/Misc.pm share_perl5_DATA += lib/Vyatta/Interface.pm share_perl5_DATA += lib/Vyatta/TypeChecker.pm diff --git a/lib/Vyatta/File.pm b/lib/Vyatta/File.pm new file mode 100644 index 0000000..49f5c2b --- /dev/null +++ b/lib/Vyatta/File.pm @@ -0,0 +1,71 @@ +# Module: File.pm +# File manipulation functions + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +package Vyatta::File; +use strict; +use warnings; + +our @EXPORT = qw(touch mkdir_p rm_rf); +our @EXPORT_OK = qw(show_error); +use base qw(Exporter); + +use Fcntl; +use File::Path qw(make_path remove_tree); + +# Change file time stamps +# if file does not exist, it is created empty +sub touch { + my $file = shift; + my $t = time; + + sysopen (my $f, $file, O_RDWR|O_CREAT) + or die "Can't touch $file: $!"; + close $f; + utime $t, $t, $file; +} + +# like mkdir -p +# Wrapper of File::Path:make_tree +sub mkdir_p { + my $path = shift; + my $err; + + make_path($path, { error => \$err } ); + + return @$err; +} + +# like rm -rf +# returns an array of errors if any (see File::Path) +sub rm_rf { + my $path = shift; + my $err; + + remove_tree($path, { error => \$err } ); + + return @$err; +} + +sub show_error { + for my $diag (@_) { + my ($f, $msg) = %$diag; + warn "$f: $msg\n"; + } +} + +1; -- cgit v1.2.3