This file is indexed.

/usr/share/perl5/Arch/Test/Tree.pm is in libarch-perl 0.5.2-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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# Arch Perl library, Copyright (C) 2005 Enno Cramer
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

use 5.005;
use strict;

package Arch::Test::Tree;

use Arch::TempFiles qw();
use Arch::Util qw();

use POSIX qw(getcwd);

sub new {
	my $class = shift;
	my $fw = shift;
	my $path = shift;

	my $self = {
		root      => $path,
		framework => $fw,
		files     => {
		}
	};

	bless $self, $class;

	return $self;
}

sub root ($) {
	my $self = shift;

	return $self->{root};
}

sub framework ($) {
	my $self = shift;

	return $self->{framework};
}

sub run_tla ($@) {
	my $self = shift;

	my $cwd = getcwd;
	chdir($self->root);
	my @ret = $self->framework->run_tla(@_);
	chdir($cwd);

	return wantarray ? @ret : $ret[0];
}

sub run_cmd ($@) {
	my $self = shift;

	my $cwd = getcwd;
	chdir($self->root);
	my @ret = Arch::Util::run_cmd(@_);
	chdir($cwd);

	die "run_cmd(".join(' ', @_).") failed: $?\n"
		if $?;

	return wantarray ? @ret : $ret[0];
}

sub gen_id ($$) {
	my $self = shift;
	my $parent = shift;

	$self->{files}->{$parent} = 0
		unless exists $self->{files}->{$parent};

	return $self->{files}->{$parent}++;
}

sub add_file ($;$$$) {
	my $self = shift;
	my $dir  = shift || '.';
	my $name = shift || 'file-' . $self->gen_id($dir);
	my $cont = shift || "Content for $name.\n";

	my $fname = "$dir/$name";

	my $path = $self->root . "/$fname";
	Arch::Util::save_file($path, $cont);

	$self->run_tla('add-id', $fname);

	return $fname;
}

sub add_dir ($;$$) {
	my $self = shift;
	my $dir  = shift || '.';
	my $name = shift || 'dir-' . $self->gen_id($dir);

	my $fname = "$dir/$name";

	my $path = $self->root . "/$fname";
	mkdir($path) || die "mkdir($path) failed: $!\n";

	$self->run_tla('add-id', $fname);

	return $fname;
}

sub add_link ($;$$$) {
	my $self = shift;
	my $dir  = shift || '.';
	my $name = shift || 'file-' . $self->gen_id($dir);
	my $cont = shift || "Link-target-for-$name";

	my $fname = "$dir/$name";

	$self->run_cmd('/bin/ln', '-s', $cont, $fname);
	$self->run_tla('add-id', $fname);

	return $fname;
}

sub modify_file($$;$) {
	my $self = shift;
	my $file = shift;
	my $content = shift || Arch::Util::load_file($self->root . "/$file")
		. "Has been modified.\n";

	Arch::Util::save_file($self->root . "/$file", $content);
}

sub rename_file ($$$) {
	my $self = shift;
	my ($old, $new) = @_;

	my $ret = $new;

	if (-d $self->root . "/$new") {
		(my $name = $old) =~ s,(.+/),,;
		$ret .= "/$name";
	}

	$ret = './' . $ret
		unless $ret =~ /^\.\//;

	$self->run_tla('mv', $old, $new);

	return $ret;
}

sub rename_dir ($$$) {
	my $self = shift;
	my ($old, $new) = @_;

	my $ret = $new;

	if (-d $self->root . "/$new") {
		(my $name = $old) =~ s,(.+/),,;
		$ret .= "/$name";
	}

	$ret = './' . $ret
		unless $ret =~ /^\.\//;

	$self->run_cmd('mv', $old, $new);

	return $ret;
}

sub remove_file ($$) {
	my $self = shift;
	my $file = shift;

	$self->run_tla('rm', $file);
}

sub remove_dir ($$) {
	my $self = shift;
	my $dir = shift;

	Arch::Util::remove_dir($self->root . "/$dir");
}

sub inventory ($;$) {
	my $self = shift;
	my $flags = shift || '-Bs';

	return $self->run_tla('inventory', $flags);
}

# this fails in baz-1.2 (that is broken), but not in baz-1.1 and baz-1.3
sub import ($;$$) {
	my $self = shift;
	return unless ref($self);  # this is not for "use"

	my @opts = ('-d', $self->root);

	push @opts, ('-s', shift)
		if @_;

	push @opts, ('-L', shift)
		if @_;

	$self->run_tla('import', @opts);
}

sub commit ($;$$) {
	my $self = shift;

	my @opts = ('-d', $self->root);

	push @opts, ('-s', shift)
		if @_;

	push @opts, ('-L', shift)
		if @_;

	$self->run_tla('commit', @opts);
}

1;

__END__

=head1 NAME

Arch::Test::Tree - A test framework for Arch-Perl

=head1 SYNOPSIS 

    use Arch::Test::Framework;

    my $fw = Arch::Test::Framework->new;
    my $tree = $fw->make_tree($dir, $version);

    my $dir = $tree->add_dir;
    $tree->add_file($dir);
    $tree->import;

=head1 DESCRIPTION

Arch::Test::Tree provides methods to quickly build and modify Arch
project trees within the Arch::Test framework.

=head1 METHODS

B<new>,
B<root>,
B<framework>,
B<run_tla>,
B<add_file>,
B<add_dir>,
B<add_link>,
B<modify_file>,
B<rename_file>,
B<rename_dir>,
B<remove_file>,
B<remove_dir>,
B<inventory>,
B<import>,
B<commit>.

=over 4

=item B<new> [I<framework>] [I<path>]

Create a new Arch::Test::Tree instance for I<path>. This method should
not be called directly.

=item B<root>

Returns the project trees root directory.

=item B<framework>

Returns the associated Arch::Test::Framework reference.

=item B<run_tla> I<@args>

Run C<tla I<@args>> from the tree root.

=item B<add_file> [I<dir> [I<name> [I<content>]]]

Add a new file I<name> in directory I<dir>. Fill file with I<content>.

I<dir> defaults to the project root (C<.>). If I<name> is not
specified, a unique filename is generated. A default content is
generated if none is given.

=item B<add_dir> [I<parent> [I<name>]]

Add a new directory under I<parent>, or C<.> if I<parent> is not
specified. If I<name> is not given, a unique name is generated.

=item B<add_link> [I<parent> [I<name> [I<target>]]]

Add a new symbolic link under I<parent>, or C<.> if I<parent> is not
specified. If I<name> is not given, a unique name is generated. If
I<target> is omitted, a (probably) non-existing target is generated.

=item B<modify_file> I<file> [I<content>]

Change I<file>s content to I<content>, or append C<Has been modified.>
if new content is omitted.

=item B<rename_file> I<old> I<new>

Rename file I<old> to I<new>. Returns I<new>.

=item B<rename_dir> I<old> I<new>

Rename directory I<old> to I<new>. Returns I<new>.

=item B<remove_file> I<file>

Delete I<file> and its associated arch id.

=item B<remove_dir> I<dir>

Recursively delete I<dir> and its content.

=item B<inventory> [I<flags>]

Returns the inventory as generated by running C<tla inventory
I<flags>>. I<flags> default to C<-Bs> if not specified.

=item B<import> [I<summary> [I<log>]]

Create a C<base-0> revision from tree using the summary line
I<summary> and I<log> as log text. If I<tree> contains a log file,
I<summary> and I<log> can be omitted.

=item B<commit> [I<summary> [I<log>]]

Commit a C<patch-n> revision from tree using the summary line
I<summary> and I<log> as log text. If I<tree> contains a log file,
I<summary> and I<log> can be omitted.

=back

=head1 AUTHORS

Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).

Enno Cramer (uebergeek@web.de--2003/arch-perl--devel).

=cut