Mtree.pm (b62674eb) | Mtree.pm (039cbdaa) |
---|---|
1# ex:ts=8 sw=4: | 1# ex:ts=8 sw=4: |
2# $OpenBSD: Mtree.pm,v 1.13 2014/03/18 18:53:29 espie Exp $ | 2# $OpenBSD: Mtree.pm,v 1.14 2023/06/13 09:07:17 espie Exp $ |
3# 4# Copyright (c) 2004-2005 Marc Espie <espie@openbsd.org> 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 3# 4# Copyright (c) 2004-2005 Marc Espie <espie@openbsd.org> 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 |
18use strict; 19use warnings; | 18use v5.36; |
20 21package OpenBSD::Mtree; 22use File::Spec; 23 24# read an mtree file, and produce the corresponding directory hierarchy 25 | 19 20package OpenBSD::Mtree; 21use File::Spec; 22 23# read an mtree file, and produce the corresponding directory hierarchy 24 |
26sub parse_fh | 25sub parse_fh($mtree, $basedir, $fh, $h = undef) |
27{ | 26{ |
28 my ($mtree, $basedir, $fh, $h) = @_; | |
29 while(<$fh>) { 30 chomp; 31 s/^\s*//o; 32 next if /^\#/o || /^\//o; 33 s/\s.*$//o; 34 next if /^$/o; 35 if ($_ eq '..') { 36 $basedir =~ s|/[^/]*$||o; --- 8 unchanged lines hidden (view full) --- 45 if (defined $h) { 46 $mtree->{File::Spec->canonpath($_)} //= {}; 47 } else { 48 $mtree->{File::Spec->canonpath($_)} = 1; 49 } 50 } 51} 52 | 27 while(<$fh>) { 28 chomp; 29 s/^\s*//o; 30 next if /^\#/o || /^\//o; 31 s/\s.*$//o; 32 next if /^$/o; 33 if ($_ eq '..') { 34 $basedir =~ s|/[^/]*$||o; --- 8 unchanged lines hidden (view full) --- 43 if (defined $h) { 44 $mtree->{File::Spec->canonpath($_)} //= {}; 45 } else { 46 $mtree->{File::Spec->canonpath($_)} = 1; 47 } 48 } 49} 50 |
53sub parse | 51sub parse($mtree, $basedir, $filename, $h = undef) |
54{ | 52{ |
55 my ($mtree, $basedir, $filename, $h) = @_; | |
56 open my $file, '<', $filename or die "can't open $filename: $!"; 57 parse_fh($mtree, $basedir, $file, $h); 58 close $file; 59} 60 611; | 53 open my $file, '<', $filename or die "can't open $filename: $!"; 54 parse_fh($mtree, $basedir, $file, $h); 55 close $file; 56} 57 581; |