/usr/share/perl5/FCM1/SrcDirLayer.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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | # ------------------------------------------------------------------------------
# (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/>.
# ------------------------------------------------------------------------------
# NAME
# FCM1::SrcDirLayer
#
# DESCRIPTION
# This class contains methods to manipulate the extract of a source
# directory from a branch of a (Subversion) repository.
#
# ------------------------------------------------------------------------------
use warnings;
use strict;
package FCM1::SrcDirLayer;
use base qw{FCM1::Base};
use FCM1::Util qw{run_command e_report w_report};
use File::Basename qw{dirname};
use File::Path qw{mkpath};
use File::Spec;
# List of property methods for this class
my @scalar_properties = (
'cachedir', # cache directory for this directory branch
'commit', # revision at which the source directory was changed
'extracted', # is this branch already extracted?
'files', # list of source files in this directory branch
'location', # location of the source directory in the branch
'name', # sub-package name of the source directory
'package', # top level package name of which the current repository belongs
'reposroot', # repository root URL
'revision', # revision of the repository branch
'tag', # package/revision tag of the current repository branch
'type', # type of the repository branch ("svn" or "user")
);
my %ERR_MESS_OF = (
CACHE_WRITE => '%s: cannot write to cache',
SYMLINK => '%s/%s: ignore symbolic link',
VC_TYPE => '%s: repository type not supported',
);
# ------------------------------------------------------------------------------
# SYNOPSIS
# $obj = FCM1::SrcDirLayer->new (%args);
#
# DESCRIPTION
# This method constructs a new instance of the FCM1::SrcDirLayer class. See
# above for allowed list of properties. (KEYS should be in uppercase.)
# ------------------------------------------------------------------------------
sub new {
my $this = shift;
my %args = @_;
my $class = ref $this || $this;
my $self = FCM1::Base->new (%args);
for (@scalar_properties) {
$self->{$_} = exists $args{uc ($_)} ? $args{uc ($_)} : undef;
}
bless $self, $class;
return $self;
}
# ------------------------------------------------------------------------------
# SYNOPSIS
# $value = $obj->X;
# $obj->X ($value);
#
# DESCRIPTION
# Details of these properties are explained in @scalar_properties.
# ------------------------------------------------------------------------------
for my $name (@scalar_properties) {
no strict 'refs';
*$name = sub {
my $self = shift;
# Argument specified, set property to specified argument
if (@_) {
$self->{$name} = $_[0];
}
# Default value for property
if (not defined $self->{$name}) {
if ($name eq 'files') {
# Reference to an array
$self->{$name} = [];
}
}
return $self->{$name};
}
}
# Handles error/warning events.
sub _err {
my ($key, $args_ref, $warn_only) = @_;
my $reporter = $warn_only ? \&w_report : \&e_report;
$args_ref ||= [];
$reporter->(sprintf($ERR_MESS_OF{$key} . ".\n", @{$args_ref}));
}
# ------------------------------------------------------------------------------
# SYNOPSIS
# $dir = $obj->localdir;
#
# DESCRIPTION
# This method returns the user or cache directory for the current revision
# of the repository branch.
# ------------------------------------------------------------------------------
sub localdir {
my $self = shift;
return $self->user ? $self->location : $self->cachedir;
}
# ------------------------------------------------------------------------------
# SYNOPSIS
# $user = $obj->user;
#
# DESCRIPTION
# This method returns the string "user" if the current source directory
# branch is a local directory. Otherwise, it returns "undef".
# ------------------------------------------------------------------------------
sub user {
my $self = shift;
return $self->type eq 'user' ? 'user' : undef;
}
# ------------------------------------------------------------------------------
# SYNOPSIS
# $rev = $obj->get_commit;
#
# DESCRIPTION
# If the current repository type is "svn", this method attempts to obtain
# the revision in which the branch is last committed. On a successful
# operation, it returns this revision number. Otherwise, it returns
# "undef".
# ------------------------------------------------------------------------------
sub get_commit {
my $self = shift;
if ($self->type eq 'svn') {
# Execute the "svn info" command
my @lines = &run_command (
[qw/svn info -r/, $self->revision, $self->location . '@' . $self->revision],
METHOD => 'qx', TIME => $self->config->verbose > 2,
);
my $rev;
for (@lines) {
if (/^Last\s+Changed\s+Rev\s*:\s*(\d+)/i) {
$rev = $1;
last;
}
}
# Commit revision of this source directory
$self->commit ($rev);
return $self->commit;
} elsif ($self->type eq 'user') {
return;
} else {
_err('VC_TYPE', [$self->type()]);
}
}
# ------------------------------------------------------------------------------
# SYNOPSIS
# $rc = $obj->update_cache;
#
# DESCRIPTION
# If the current repository type is "svn", this method attempts to extract
# the current revision source directory from the current branch from the
# repository, sending the output to the cache directory. It returns true on
# a successful operation, or false if the repository is not of type "svn".
# ------------------------------------------------------------------------------
sub update_cache {
my $self = shift;
return unless $self->cachedir;
# Create cache extract destination, if necessary
my $dirname = dirname $self->cachedir;
mkpath($dirname);
if (!-d $dirname) {
_err('CACHE_WRITE', [$dirname]);
}
if ($self->type eq 'svn') {
# Set up the extract command, "svn export --force -q -N"
my @command = (
qw/svn export --force -q -N/,
$self->location . '@' . $self->revision,
$self->cachedir,
);
&run_command (\@command, TIME => $self->config->verbose > 2);
} elsif ($self->type eq 'user') {
return;
} else {
_err('VC_TYPE', [$self->type()]);
}
return 1;
}
# ------------------------------------------------------------------------------
# SYNOPSIS
# @files = $obj->get_files();
#
# DESCRIPTION
# This method returns a list of file base names in the (cache of) this source
# directory in the current branch.
# ------------------------------------------------------------------------------
sub get_files {
my ($self) = @_;
opendir(my $dir, $self->localdir())
|| die($self->localdir(), ': cannot read directory');
my @base_names = ();
BASE_NAME:
while (my $base_name = readdir($dir)) {
if ($base_name =~ qr{\A\.}xms || $base_name =~ qr{~\z}xms) {
next BASE_NAME;
}
my $path = File::Spec->catfile($self->localdir(), $base_name);
if (-d $path) {
next BASE_NAME;
}
if (-l $path) {
_err('SYMLINK', [$self->location(), $base_name], 1);
next BASE_NAME;
}
push(@base_names, $base_name);
}
closedir($dir);
$self->files(\@base_names);
return @base_names;
}
# ------------------------------------------------------------------------------
1;
__END__
|