/usr/share/perl5/FCM/Util/Locator/FS.pm is in fcm 2016.12.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | # ------------------------------------------------------------------------------
# (C) British Crown Copyright 2006-16 Met Office.
#
# This file is part of FCM, tools for managing and building source code.
#
# FCM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FCM 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.
#
# You should have received a copy of the GNU General Public License
# along with FCM. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------
use strict;
use warnings;
# ------------------------------------------------------------------------------
package FCM::Util::Locator::FS;
use base qw{FCM::Class::CODE};
use File::Basename qw{dirname};
use File::Find qw{};
use File::Spec;
our %ACTION_OF = (
can_work_with => sub {1},
can_work_with_rev => sub {},
cat => \&_cat,
dir => \&_dir,
find => \&_find,
origin => \&_parse,
parse => \&_parse,
reader => \&_reader,
read_property => sub {},
test_exists => \&_test_exists,
trunk_at_head => sub {},
);
# Creates the class.
__PACKAGE__->class({util => '&'}, {action_of => \%ACTION_OF});
# Joins @paths to the end of $value.
sub _cat {
my ($attrib_ref, $value, @paths) = @_;
_parse(
$attrib_ref,
File::Spec->catfile(scalar(_parse($attrib_ref, $value)), @paths),
);
}
# Returns the directory name of $value.
sub _dir {
my ($attrib_ref, $value) = @_;
dirname(scalar(_parse($attrib_ref, $value)));
}
# Searches directory tree.
sub _find {
my ($attrib_ref, $value, $callback) = @_;
my $found;
File::Find::find(
sub {
$found ||= 1;
my $path = $File::Find::name;
my $ns = File::Spec->abs2rel($path, $value);
if ($ns eq q{.}) {
$ns = q{};
}
else {
for my $name (split(q{/}, $ns)) {
if (index($name, q{.}) == 0) {
return; # ignore Unix hidden/system files
}
}
}
my $last_mod_time = (-l $path ? lstat($path) : stat($path))[9];
$callback->(
$path,
{ is_dir => scalar(-d $path),
last_mod_rev => undef,
last_mod_time => $last_mod_time,
ns => $ns,
},
);
},
$value,
);
return $found;
}
# Returns $value in scalar context, or ($value,undef) in list context.
sub _parse {
my ($attrib_ref, $value) = @_;
$value = $attrib_ref->{util}->file_tilde_expand($value);
$value = File::Spec->rel2abs($value);
my ($vol, $dir_name, $base) = File::Spec->splitpath($value);
my @dir_names;
my %HANDLER_OF = (
q{} => sub {push(@dir_names, $_[0])},
q{.} => sub {},
q{..} => sub {if (@dir_names > 1) {pop(@dir_names)}},
);
for my $name (File::Spec->splitdir($dir_name)) {
my $handler
= exists($HANDLER_OF{$name}) ? $HANDLER_OF{$name} : $HANDLER_OF{q{}};
$handler->($name);
}
$value = File::Spec->catpath($vol, File::Spec->catdir(@dir_names), $base);
return (wantarray() ? ($value, undef) : $value);
}
# Returns a reader (file handle) for a given file system value.
sub _reader {
my ($attrib_ref, $value) = @_;
$value = _parse($attrib_ref, $value);
open(my $handle, '<', $value) || die("$!\n");
return $handle;
}
# Return a true value if the location $value exists.
sub _test_exists {
my ($attrib_ref, $value) = @_;
-e $value;
}
# ------------------------------------------------------------------------------
1;
__END__
=head1 NAME
FCM::Util::Locator::FS
=head1 SYNOPSIS
use FCM::Util::Locator::FS;
$util = FCM::Util::Locator::FS->new(\%option);
$handle = $util->reader($value);
=head1 DESCRIPTION
Provides utilities to manipulate the values of file system locators.
=head1 METHODS
=over 4
=item $util->can_work_with($value)
Dummy. Always returns true.
=item $util->can_work_with_rev($revision)
Dummy. Always returns false.
=item $util->cat($value,@paths)
Joins @paths to the end of $value.
=item $util->dir($value)
Returns the parent directory of $value.
=item $util->find($value,$callback)
Searches directory tree of $value.
=item $util->origin($value)
Alias of $util->parse($value).
=item $util->parse($value)
In scalar context, returns $value. In list context, returns ($value,undef).
=item $util->reader($value)
Returns a file handle for $value, if it is a readable regular file.
=item $util->read_property($value,$property_name)
Dummy. Always returns undef.
=item $util->test_exists($value)
Return a true value if the location $value exists.
=item $util->trunk_at_head($value)
Dummy. Always returns undef.
=back
=head1 COPYRIGHT
(C) Crown copyright Met Office. All rights reserved.
=cut
|