line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Arch Perl library, Copyright (C) 2005 Enno Cramer |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
4
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
5
|
|
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
6
|
|
|
|
|
|
|
# (at your option) any later version. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
9
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11
|
|
|
|
|
|
|
# GNU General Public License for more details. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
14
|
|
|
|
|
|
|
# along with this program; if not, write to the Free Software |
15
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
12
|
use 5.005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
18
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Arch::Test::Tree; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
7
|
use Arch::TempFiles qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
23
|
1
|
|
|
1
|
|
5
|
use Arch::Util qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5
|
use POSIX qw(getcwd); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
29
|
0
|
|
|
|
|
0
|
my $fw = shift; |
30
|
0
|
|
|
|
|
0
|
my $path = shift; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
my $self = { |
33
|
|
|
|
|
|
|
root => $path, |
34
|
|
|
|
|
|
|
framework => $fw, |
35
|
|
|
|
|
|
|
files => { |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
bless $self, $class; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub root ($) { |
45
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
return $self->{root}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub framework ($) { |
51
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
return $self->{framework}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub run_tla ($@) { |
57
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my $cwd = getcwd; |
60
|
0
|
|
|
|
|
0
|
chdir($self->root); |
61
|
0
|
|
|
|
|
0
|
my @ret = $self->framework->run_tla(@_); |
62
|
0
|
|
|
|
|
0
|
chdir($cwd); |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
return wantarray ? @ret : $ret[0]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub run_cmd ($@) { |
68
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
my $cwd = getcwd; |
71
|
0
|
|
|
|
|
0
|
chdir($self->root); |
72
|
0
|
|
|
|
|
0
|
my @ret = Arch::Util::run_cmd(@_); |
73
|
0
|
|
|
|
|
0
|
chdir($cwd); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
0
|
die "run_cmd(".join(' ', @_).") failed: $?\n" |
76
|
|
|
|
|
|
|
if $?; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
return wantarray ? @ret : $ret[0]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub gen_id ($$) { |
82
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
83
|
0
|
|
|
|
|
0
|
my $parent = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
$self->{files}->{$parent} = 0 |
86
|
|
|
|
|
|
|
unless exists $self->{files}->{$parent}; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
return $self->{files}->{$parent}++; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub add_file ($;$$$) { |
92
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
93
|
0
|
|
0
|
|
|
0
|
my $dir = shift || '.'; |
94
|
0
|
|
0
|
|
|
0
|
my $name = shift || 'file-' . $self->gen_id($dir); |
95
|
0
|
|
0
|
|
|
0
|
my $cont = shift || "Content for $name.\n"; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
0
|
my $fname = "$dir/$name"; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
my $path = $self->root . "/$fname"; |
100
|
0
|
|
|
|
|
0
|
Arch::Util::save_file($path, $cont); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
$self->run_tla('add-id', $fname); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
return $fname; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub add_dir ($;$$) { |
108
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
109
|
0
|
|
0
|
|
|
0
|
my $dir = shift || '.'; |
110
|
0
|
|
0
|
|
|
0
|
my $name = shift || 'dir-' . $self->gen_id($dir); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
my $fname = "$dir/$name"; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
my $path = $self->root . "/$fname"; |
115
|
0
|
0
|
|
|
|
0
|
mkdir($path) || die "mkdir($path) failed: $!\n"; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
$self->run_tla('add-id', $fname); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
return $fname; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub add_link ($;$$$) { |
123
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
124
|
0
|
|
0
|
|
|
0
|
my $dir = shift || '.'; |
125
|
0
|
|
0
|
|
|
0
|
my $name = shift || 'file-' . $self->gen_id($dir); |
126
|
0
|
|
0
|
|
|
0
|
my $cont = shift || "Link-target-for-$name"; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
my $fname = "$dir/$name"; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
0
|
$self->run_cmd('/bin/ln', '-s', $cont, $fname); |
131
|
0
|
|
|
|
|
0
|
$self->run_tla('add-id', $fname); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
return $fname; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub modify_file($$;$) { |
137
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
138
|
0
|
|
|
|
|
0
|
my $file = shift; |
139
|
0
|
|
0
|
|
|
0
|
my $content = shift || Arch::Util::load_file($self->root . "/$file") |
140
|
|
|
|
|
|
|
. "Has been modified.\n"; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
Arch::Util::save_file($self->root . "/$file", $content); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub rename_file ($$$) { |
146
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
147
|
0
|
|
|
|
|
0
|
my ($old, $new) = @_; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
0
|
my $ret = $new; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
0
|
if (-d $self->root . "/$new") { |
152
|
0
|
|
|
|
|
0
|
(my $name = $old) =~ s,(.+/),,; |
153
|
0
|
|
|
|
|
0
|
$ret .= "/$name"; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
0
|
$ret = './' . $ret |
157
|
|
|
|
|
|
|
unless $ret =~ /^\.\//; |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
$self->run_tla('mv', $old, $new); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
return $ret; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub rename_dir ($$$) { |
165
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
166
|
0
|
|
|
|
|
0
|
my ($old, $new) = @_; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
0
|
my $ret = $new; |
169
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
0
|
if (-d $self->root . "/$new") { |
171
|
0
|
|
|
|
|
0
|
(my $name = $old) =~ s,(.+/),,; |
172
|
0
|
|
|
|
|
0
|
$ret .= "/$name"; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
0
|
$ret = './' . $ret |
176
|
|
|
|
|
|
|
unless $ret =~ /^\.\//; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
0
|
$self->run_cmd('mv', $old, $new); |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
return $ret; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub remove_file ($$) { |
184
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
185
|
0
|
|
|
|
|
0
|
my $file = shift; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
0
|
$self->run_tla('rm', $file); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub remove_dir ($$) { |
191
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
192
|
0
|
|
|
|
|
0
|
my $dir = shift; |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
0
|
Arch::Util::remove_dir($self->root . "/$dir"); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub inventory ($;$) { |
198
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
199
|
0
|
|
0
|
|
|
0
|
my $flags = shift || '-Bs'; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
return $self->run_tla('inventory', $flags); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# this fails in baz-1.2 (that is broken), but not in baz-1.1 and baz-1.3 |
205
|
|
|
|
|
|
|
sub import ($;$$) { |
206
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
207
|
3
|
50
|
|
|
|
525
|
return unless ref($self); # this is not for "use" |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my @opts = ('-d', $self->root); |
210
|
|
|
|
|
|
|
|
211
|
0
|
0
|
|
|
|
|
push @opts, ('-s', shift) |
212
|
|
|
|
|
|
|
if @_; |
213
|
|
|
|
|
|
|
|
214
|
0
|
0
|
|
|
|
|
push @opts, ('-L', shift) |
215
|
|
|
|
|
|
|
if @_; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
$self->run_tla('import', @opts); |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub commit ($;$$) { |
221
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my @opts = ('-d', $self->root); |
224
|
|
|
|
|
|
|
|
225
|
0
|
0
|
|
|
|
|
push @opts, ('-s', shift) |
226
|
|
|
|
|
|
|
if @_; |
227
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
push @opts, ('-L', shift) |
229
|
|
|
|
|
|
|
if @_; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
$self->run_tla('commit', @opts); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
__END__ |