summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2005-02-26 13:56:29 +0000
committerMarc Espie <espie@cvs.openbsd.org>2005-02-26 13:56:29 +0000
commitde82f8d3f6bc1bd9b4a8711c4c8178650f3375e8 (patch)
tree5b42818b4606868f7db26e232fc178ebf508a9e6 /usr.sbin/pkg_add/OpenBSD
parent6af8e4cf424b3f4a3d28354fd08799a9338c694e (diff)
cosmetic clean-up
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Mtree.pm24
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;
}