diff options
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Mtree.pm | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Mtree.pm b/usr.sbin/pkg_add/OpenBSD/Mtree.pm index 3899bf78889..ce63c19d4a6 100644 --- a/usr.sbin/pkg_add/OpenBSD/Mtree.pm +++ b/usr.sbin/pkg_add/OpenBSD/Mtree.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Mtree.pm,v 1.1 2004/09/14 22:24:21 espie Exp $ +# $OpenBSD: Mtree.pm,v 1.2 2005/02/26 13:56:28 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -22,26 +22,34 @@ package OpenBSD::Mtree; use File::Spec; # read an mtree file, and produce the corresponding directory hierarchy -sub parse + +sub parse_fh { - my ($mtree, $current_dir, $filename) = @_; - open my $file, '<', $filename; - while(<$file>) { + my ($mtree, $basedir, $fh) = @_; + local $_; + while(<$fh>) { chomp; s/^\s*//; next if /^\#/ || /^\//; s/\s.*$//; next if /^$/; if ($_ eq '..') { - $current_dir =~ s|/[^/]*$||; + $basedir =~ s|/[^/]*$||; next; } else { - $current_dir.="/$_"; + $basedir.="/$_"; } - $_ = $current_dir; + $_ = $basedir; while (s|/\./|/|) {} $mtree->{File::Spec->canonpath($_)} = 1; } +} + +sub parse +{ + my ($mtree, $basedir, $filename) = @_; + open my $file, '<', $filename or die "can't open $filename: $!"; + parse_fh($mtree, $basedir, $file); close $file; } |