/[soft]/build_system/iurt/trunk/lib/Iurt/Urpmi.pm
ViewVC logotype

Contents of /build_system/iurt/trunk/lib/Iurt/Urpmi.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations) (download)
Tue Nov 23 23:36:41 2010 UTC (13 years, 5 months ago) by blino
File size: 22126 byte(s)
use iurt_root_command to add additional media

1 package Iurt::Urpmi;
2
3 use strict;
4 use RPM4::Header;
5 use File::Basename;
6 use File::NCopy qw(copy);
7 use MDV::Distribconf::Build;
8 use Iurt::Chroot qw(add_local_user create_temp_chroot check_build_chroot);
9 use Iurt::Process qw(perform_command clean clean_process sudo);
10 use Iurt::Config qw(dump_cache_par get_maint get_package_prefix);
11 use Iurt::Util qw(plog);
12
13
14 sub new {
15 my ($class, %opt) = @_;
16 my $self = bless {
17 config => $opt{config},
18 run => $opt{run},
19 urpmi_options => $opt{urpmi_options},
20 }, $class;
21 my $config = $self->{config};
22 my $run = $self->{run};
23
24 if ($run->{use_system_distrib}) {
25 $config->{basesystem_media_root} ||= $run->{use_system_distrib};
26 } elsif ($run->{chrooted_urpmi}) {
27 my ($host) = $run->{chrooted_urpmi}{rooted_media} =~ m,(?:file|http|ftp)://([^/]*),;
28 my ($_name, $_aliases, $_addrtype, $_length, @addrs) = gethostbyname($host);
29
30 my $ip = join('.', unpack('C4', $addrs[0]));
31
32 $ip =~ /\d+\.\d+\.\d+\.\d+/
33 or die "FATAL: could not resolve $host ip address";
34
35 $run->{chrooted_urpmi}{rooted_media} =~ s/$host/$ip/;
36 $run->{chrooted_media} = $run->{chrooted_urpmi}{rooted_media} .
37 "/$run->{distro}/$run->{my_arch}";
38
39 # Now squash all slashes that don't follow colon
40 $run->{chrooted_media} =~ s|(?<!:)/+|/|g;
41
42 plog('DEBUG', "installation media: $run->{chrooted_media}");
43 }
44 $self->{use__urpmi_root} = $config->{repository} =~ m/^(http|ftp):/;
45 $self->{distrib_url} = "$config->{repository}/$run->{distro}/$run->{my_arch}";
46
47 $self;
48 }
49
50 sub set_command {
51 my ($self, $_chroot_tmp) = @_;
52 $self->{use__urpmi_root} ? &set_command__urpmi_root : &set_command__use_distrib;
53 }
54 sub set_command__urpmi_root {
55 my ($self, $chroot_tmp) = @_;
56 $self->{use_iurt_root_command} = 1;
57 $self->{urpmi_command} = "urpmi $self->{urpmi_options} --urpmi-root $chroot_tmp";
58 }
59 sub set_command__use_distrib {
60 my ($self, $chroot_tmp) = @_;
61 $self->{use_iurt_root_command} = 1;
62 $self->{urpmi_command} = "urpmi $self->{urpmi_options} --use-distrib $self->{distrib_url} --root $chroot_tmp";
63 }
64 sub set_command__chrooted {
65 my ($self, $chroot_tmp) = @_;
66 $self->{urpmi_command} = "chroot $chroot_tmp urpmi $self->{urpmi_options} ";
67 }
68
69 sub set_local_media {
70 my ($self, $local_media) = @_;
71 $self->{local_media} = $local_media;
72 }
73
74 sub add_to_local_media {
75 my ($self, $chroot_tmp, $srpm, $luser) = @_;
76 my $local_media = $self->{local_media};
77
78 system("cp $chroot_tmp/home/$luser/rpm/RPMS/*/*.rpm $local_media &>/dev/null") and plog("ERROR: could not copy rpm files from $chroot_tmp/home/$luser/rpm/RPMS/ to $local_media ($!)");
79 system("cp $chroot_tmp/home/$luser/rpm/SRPMS/$srpm $local_media &>/dev/null") and plog("ERROR: could not copy $srpm from $chroot_tmp/home/$luser/rpm/SRPMS/ to $local_media ($!)");
80 }
81
82 sub urpmi_command {
83 my ($self, $chroot_tmp, $_luser) = @_;
84 my $run = $self->{run};
85 my $local_media = $self->{local_media};
86
87 #plog(3, "urpmi_command ($chroot_tmp user $luser)");
88 if ($run->{chrooted_urpmi}) {
89 $self->set_command($chroot_tmp);
90
91 # CM: commented out
92 # this was causing rpm database corruption problems and the packages
93 # are already installed
94 #
95 # if (!install_packages($self, 'chroot', $chroot_tmp, $local_spool, {}, 'configure', "[ADMIN] installation of urpmi and sudo failed in the chroot $run->{my_arch}", { maintainer => $config->{admin}, check => 1 }, 'urpmi', 'sudo')) {
96 # $run->{chrooted_urpmi} = 0;
97 # return
98 # }
99
100 # Here should be added only the needed media for the given package
101 # main/release -> main/release
102 # main/testing -> main/release main/testing
103 # contrib/release -> contrib/release main/release
104 # contrib/testing -> contrib/testing contrib/release main/testing main/release
105 # non-free/release ...
106 # This is now done with an option in iurt2 --chrooted-urpmi -m media1 media2 -- media_url
107
108 if ($run->{chrooted_urpmi}{media}) {
109 foreach my $m (@{$run->{chrooted_urpmi}{media}}) {
110 my $m_name = $m;
111 $m_name =~ s,/,_,g;
112 if (!add_media($self, $chroot_tmp, $m_name,
113 "$m_name $run->{chrooted_media}/media/$m")) {
114 $run->{chrooted_urpmi} = 0;
115 plog('ERROR', "Failed to add media $m_name. Disabling chrooted_urpmi.");
116 return;
117 }
118 }
119 } else {
120 if (!add_media($self, $chroot_tmp, 'Main', "--distrib $run->{chrooted_media}")) {
121 if (!add_media($self, $chroot_tmp, 'Main', "--wget --distrib $run->{chrooted_media}")) {
122 $run->{chrooted_urpmi} = 0;
123 plog('ERROR', "Failed to add media $run->{chrooted_media}. Disabling chrooted_urpmi.");
124 return;
125 }
126 }
127 }
128
129 foreach my $m (@{$run->{additional_media}{media}}) {
130 my $name = "$run->{additional_media}{repository}_$m";
131 $name =~ s![/:]!_!g;
132
133 my $url;
134 if ($run->{additional_media}{repository} =~ m!^(http:|ftp:)!) {
135 $url = $run->{additional_media}{repository};
136 }
137 else {
138 $url = "/urpmi_medias/$run->{distro}/$m";
139 }
140
141 # Check if the media is not empty, as add_media will abort if it fails
142 my $DP;
143 if (!opendir($DP, "$chroot_tmp/$url")) {
144 plog('ERROR', "Failed to add additional media at $url: $!");
145 next;
146 }
147 my @contents = readdir $DP;
148 close($DP);
149 if (@contents <= 2) {
150 # Just entries: . ..
151 plog('DEBUG', "$url has no packages, skipping it.");
152 next;
153 }
154
155 if (!add_media($self, $chroot_tmp, $name, "$name $url")) {
156 plog("ERROR: Unable to add media $m");
157 }
158 }
159
160 if (-d $local_media) {
161 mkdir("$chroot_tmp/iurt_media/");
162 opendir my $dir, $local_media;
163 my $next;
164 foreach my $f (readdir $dir) {
165 $f =~ /(\.rpm|^hdlist.cz)$/ or next;
166 if (!link "$local_media/$f", "$chroot_tmp/iurt_media") {
167 if (!copy "$local_media/$f", "$chroot_tmp/iurt_media") {
168 plog('ERROR', "could not copy file $local_media/$f to $chroot_tmp/iurt_media");
169 $next = 1;
170 last;
171 }
172 }
173 }
174 next if $next;
175 add_media($self, $chroot_tmp, 'iurt_group', "iurt_group file:///iurt_media") or next;
176 }
177
178 $self->set_command__chrooted($chroot_tmp);
179 return 1;
180 } else {
181 $self->set_command($chroot_tmp);
182 }
183 }
184
185 sub check_media_added {
186 my ($chroot, $media) = @_;
187 my $medias = `sudo chroot $chroot urpmq --list-media 2>&1`;
188 print "MEDIA $medias ($media)\n";
189 $medias =~ /$media/m;
190 }
191
192 sub add_media__urpmi_root {
193 my ($self, $chroot) = @_;
194 my $run = $self->{run};
195 my $config = $self->{config};
196 my $cache = $run->{cache};
197
198 plog("adding distrib $self->{distrib_url} with option --urpmi-root in chroot $chroot");
199
200 perform_command("urpmi-addmedia -v --urpmi-root $chroot --distrib $self->{distrib_url} --probe-synthesis",
201 $run, $config, $cache,
202 mail => $config->{admin},
203 timeout => 300,
204 use_iurt_root_command => 1,
205 freq => 1,
206 retry => 2,
207 debug_mail => $run->{debug});
208 }
209
210 sub add_media {
211 my ($self, $chroot, $regexp, $media) = @_;
212 my $run = $self->{run};
213 my $config = $self->{config};
214 my $cache = $run->{cache};
215
216 plog("add chroot media: $run->{chrooted_media}");
217
218 if (!perform_command("urpmi-addmedia $media",
219 $run, $config, $cache,
220 mail => $config->{admin},
221 timeout => 300,
222 freq => 1,
223 retry => 2,
224 use_iurt_root_command => 1,
225 debug_mail => $run->{debug})) {
226 }
227 if (!check_media_added($chroot, $regexp)) {
228 plog('ERR', "ERROR iurt could not add media into the chroot");
229 return;
230 }
231 1;
232 }
233
234 sub add_packages {
235 my ($self, $chroot, $_user, @packages) = @_;
236 my $run = $self->{run};
237 my $config = $self->{config};
238 my $cache = $run->{cache};
239 if (!perform_command("$self->{urpmi_command} @packages",
240 $run, $config, $cache,
241 use_iurt_root_command => $self->{use_iurt_root_command},
242 timeout => 300,
243 freq => 1,
244 retry => 2,
245 error_ok => [ 11 ],
246 debug_mail => $run->{debug},
247 error_regexp => 'cannot be installed',
248 wait_regexp => {
249 'database locked' => sub {
250 plog("WARNING: urpmi database locked, waiting...");
251 sleep 30;
252 $self->{wait_limit}++;
253 if ($self->{wait_limit} > 10) {
254 #$self->{wait_limit} = 0;
255 # <mrl> We can't shoot such command, it's too powerfull.
256 #system(qq(sudo pkill -9 urpmi &>/dev/null));
257 return 0;
258 }
259 1;
260 } },)) {
261 plog("ERROR: could not install @packages inside $chroot");
262 return 0;
263 }
264 1;
265 }
266
267 sub get_local_provides {
268 my ($self) = @_;
269 my $run = $self->{run};
270 my $program_name = $run->{program_name};
271 my $local_media = $self->{local_media};
272
273 opendir my $dir, $local_media;
274 plog(1, "get local provides ($local_media)");
275 require URPM;
276 my $urpm = new URPM;
277 foreach my $d (readdir $dir) {
278 $d =~ /\.src\.rpm$/ and next;
279 $d =~ /\.rpm$/ or next;
280 my $id = $urpm->parse_rpm("$local_media/$d");
281 my $pkg = $urpm->{depslist}[$id];
282 plog(3, "$program_name: checking $d provides");
283 foreach ($pkg->provides, $pkg->files) {
284 plog(3, "$program_name: adding $_ as provides of $d");
285 $run->{local_provides}{$_} = $d;
286 }
287 }
288 1;
289 }
290
291 sub get_build_requires {
292 my ($self, $union_id, $luser) = @_;
293 my $run = $self->{run};
294 my $config = $self->{config};
295 my $cache = $run->{cache};
296
297 $run->{todo_requires} = {};
298 plog("get_build_requires");
299
300 my ($u_id, $chroot_tmp) = create_temp_chroot($run, $config, $cache, $union_id, $run->{chroot_tmp}, $run->{chroot_tar}) or return;
301 add_local_user($chroot_tmp, $run, $config, $luser, $run->{uid}) or return;
302 $union_id = $u_id;
303
304 my $urpm = new URPM;
305 foreach my $p (@{$run->{todo}}) {
306 my ($dir, $srpm, $s) = @$p;
307 recreate_srpm($self, $run, $config, $chroot_tmp, $dir, $srpm, $run->{user}) or return;
308 $s or next;
309 my $id = $urpm->parse_rpm("$dir/$srpm");
310 my $pkg = $urpm->{depslist}[$id];
311 foreach ($pkg->requires) {
312 plog(3, "adding $_ as requires of $srpm");
313 $run->{todo_requires}{$_} = $srpm;
314 }
315 }
316 1;
317 }
318
319 sub order_packages {
320 my ($self, $union_id, $provides, $luser) = @_;
321 my $run = $self->{run};
322 my @packages = @{$run->{todo}};
323 my $move;
324
325 plog(1, "order_packages");
326 get_local_provides($self) or return;
327 if (!$run->{todo_requires}) {
328 get_build_requires($self, $union_id, $luser) or return;
329 }
330 my %visit;
331 my %status;
332 do {
333 $move = 0;
334 foreach my $p (@packages) {
335 my ($_dir, $rpm, $status) = @$p;
336 defined $status{$rpm} && $status{$rpm} == 0 and next;
337 plog("checking packages $rpm");
338 foreach my $r (@{$run->{todo_requires}{$rpm}}) {
339 plog("checking requires $r");
340 if (!$run->{local_provides}{$r}) {
341 if ($provides->{$r}) {
342 $status = 1;
343 } else {
344 $status = 0;
345 }
346 } elsif ($visit{$rpm}{$r}) {
347 # to evit loops
348 $status = 0;
349 } elsif ($run->{done}{$rpm} && $run->{done}{$provides->{$r}}) {
350 if ($run->{done}{$rpm} < $run->{done}{$provides->{$r}}) {
351 $move = 1;
352 $status = $status{$provides->{$r}} + 1;
353 } else {
354 $status = 0;
355 }
356 } elsif ($status < $status{$provides->{$r}}) {
357 $move = 1;
358 $status = $status{$provides->{$r}} + 1;
359 }
360 $visit{$rpm}{$r} = 1;
361 }
362 $status{$rpm} = $status;
363 $p->[2] = $status;
364 }
365 } while $move;
366 $run->{todo} = [ sort { $a->[2] <=> $b->[2] } @packages ];
367 if ($run->{verbose}) {
368 foreach (@packages) {
369 plog("order_packages $_->[1]");
370 }
371 }
372 @packages;
373 }
374
375 sub wait_urpmi {
376 my ($self) = @_;
377 my $run = $self->{run};
378
379 plog("WARNING: urpmi database locked, waiting...") if $run->{debug};
380 sleep 30;
381 $self->{wait_limit}++;
382 if ($self->{wait_limit} > 8) {
383 #$self->{wait_limit} = 0;
384 # <mrl> We can't shoot such command, it's too powerfull.
385 #system(qq(sudo pkill -9 urpmi &>/dev/null));
386 return 0;
387 }
388 }
389
390 sub install_packages_old {
391 my ($self, $local_spool, $srpm, $log, $error, @packages) = @_;
392 my $run = $self->{run};
393 my $config = $self->{config};
394 my $cache = $run->{cache};
395 my $log_spool = "$local_spool/log/$srpm/";
396 -d $log_spool or mkdir $log_spool;
397 if (!perform_command("$self->{urpmi_command} @packages",
398 $run, $config, $cache,
399 # mail => $maintainer,
400 use_iurt_root_command => $self->{use_iurt_root_command},
401 error => $error,
402 hash => "${log}_$srpm",
403 srpm => $srpm,
404 timeout => 600,
405 retry => 2,
406 debug_mail => $run->{debug},
407 freq => 1,
408 wait_regexp => { 'database locked' => \&wait_urpmi },
409 error_regexp => 'unable to access',
410 log => $log_spool)) {
411 $cache->{failure}{$srpm} = 1;
412 $run->{status}{$srpm} = 'binary_test_failure';
413 return 0;
414 }
415 1;
416 }
417
418 sub are_installed {
419 my ($chroot, @pkgs) = @_;
420 @pkgs = map { -f "$chroot$_" && `rpm -qp --qf %{name} $chroot$_` || $_ } @pkgs;
421 system("rpm -q --root $chroot @pkgs") == 0;
422 }
423
424 sub install_packages {
425 my ($self, $title, $chroot_tmp, $local_spool, $pack_provide, $log, $error, $opt, @packages) = @_;
426
427 my $maintainer = $opt->{maintainer};
428 my $run = $self->{run};
429 my $config = $self->{config};
430 my $cache = $run->{cache};
431 my $program_name = $run->{program_name};
432 my $ok = 1;
433 my @to_install;
434
435 plog('DEBUG', "installing @packages");
436
437 if ($run->{chrooted_urpmi}) {
438 @to_install = map { s/$chroot_tmp//; $_ } @packages;
439 } else {
440 push @to_install, @packages;
441 }
442
443 @to_install or return 1;
444
445 (my $log_dirname = $title) =~ s/.*:(.*)\.src.rpm/$1/;
446
447 my $log_spool = "$local_spool/log/$log_dirname/";
448
449 mkdir $log_spool;
450
451 my @rpm = grep { !/\.src\.rpm$/ } @to_install;
452
453 if ($opt->{check}
454 && -f "$chroot_tmp/bin/rpm"
455 && @rpm
456 && are_installed($chroot_tmp, @to_install)) {
457 return 1;
458 }
459
460 plog('INFO', "install dependencies using urpmi");
461
462 if (!perform_command(
463 "$self->{urpmi_command} @to_install",
464 $run, $config, $cache,
465 use_iurt_root_command => $self->{use_iurt_root_command},
466 error => $error,
467 logname => ${log},
468 hash => "${log}_$title",
469 timeout => 3600, # [pixel] 10 minutes was not enough, 1 hour should be better
470 srpm => $title,
471 freq => 1,
472 #cc => $cc,
473 retry => 3,
474 debug_mail => $run->{debug},
475 error_regexp => 'cannot be installed',
476 wait_regexp => {
477 'database locked' => \&wait_urpmi,
478 },
479 log => $log_spool,
480 callback => sub {
481 my ($opt, $output) = @_;
482 plog('DEBUG', "calling callback for $opt->{hash}");
483
484 # 20060614
485 # it seems the is needed urpmi error is due to something else (likely a
486 # database corruption error).
487 # my @missing_deps = $output =~ /(?:(\S+) is needed by )|(?:\(due to unsatisfied ([^[ ]*)(?: (.*)|\[(.*)\])?\))/g;
488 #
489
490 my @missing_deps = $output =~ /([^ \n]+) \(due to unsatisfied ([^[ \n]*)(?: ([^\n]*)|\[([^\n]*)\])?\)/g;
491
492 # <mrl> 20071106 FIXME: This should not be needed anymore
493 # as it seems that rpm db corruption is making urpmi
494 # returning false problem on deps installation, try
495 # to compile anyway
496
497 if (!@missing_deps) {
498 plog('DEBUG', 'missing_deps is empty, aborting.');
499 plog('DEBUG', "output had: __ $output __");
500 return 1;
501 }
502
503 while (my $missing_package = shift @missing_deps) {
504 my $missing_deps = shift @missing_deps;
505 my $version = shift @missing_deps;
506 my $version2 = shift @missing_deps;
507 $version ||= $version2 || 0;
508 my $p = $pack_provide->{$missing_deps} || $missing_deps;
509 my ($missing_package_name, $first_maint);
510 if ($missing_package !~ /\.src$/) {
511 ($first_maint, $missing_package_name) = get_maint($run, $missing_package);
512 plog(5, "likely $missing_package_name need to be rebuilt ($first_maint)");
513 } else {
514 $missing_package = '';
515 }
516
517 my ($other_maint) = get_maint($run, $p);
518 plog('FAIL', "missing dep: $missing_deps ($other_maint) missing_package $missing_package ($first_maint)");
519 $run->{status}{$title} = 'missing_dep';
520
521 $opt->{mail} = $maintainer || $config->{admin};
522
523 # remember what is needed, and do not try to
524 # recompile until it is available
525
526 if ($missing_package) {
527 $opt->{error} = "[MISSING] $missing_deps, needed by $missing_package to build $title, is not available on $run->{my_arch} (rebuild $missing_package?)";
528 $cache->{needed}{$title}{$missing_deps} = { package => $missing_package , version => $version, maint => $first_maint || $other_maint || $maintainer };
529 } else {
530 $opt->{error} = "[MISSING] $missing_deps, needed to build $title, is not available on $run->{my_arch}";
531 $cache->{needed}{$title}{$missing_deps} = { package => $missing_package , version => $version, maint => $maintainer || $other_maint };
532 }
533 }
534 0;
535 },
536 )) {
537 plog('DEBUG', "urpmi command failed.");
538 if (!clean_process($run, "$self->{urpmi_command} @to_install", $run->{verbose})) {
539 dump_cache_par($run);
540 die "FATAL $program_name: Could not have urpmi working !";
541 }
542 $ok = 0;
543 }
544
545 # <mrl> URPMI saying ok or not, we check this anyway. So that's why
546 # it's outside the else.
547 if (! -f "$chroot_tmp/bin/rpm") {
548 plog(1, "ERROR: rpm-build is missing!");
549 $ok = 0;
550 }
551 elsif ($ok && (!@rpm || are_installed($chroot_tmp, @rpm))) {
552 plog("installation successful");
553 $ok = 1;
554 }
555 else {
556 plog(1, "ERROR: Failed to install initial packages");
557 $ok = 0;
558 }
559
560 $ok;
561 }
562
563 sub clean_urpmi_process {
564 my ($self) = @_;
565 my $run = $self->{run};
566 my $program_name = $run->{program_name};
567 if (!$run->{chrooted_urpmi}) {
568 my $match = $self->{urpmi_command} or return;
569 if (!clean_process($run, $match, $run->{verbose})) {
570 dump_cache_par($run);
571 die "FATAL $program_name: Could not have urpmi working !";
572 }
573 }
574 }
575
576 sub update_srpm {
577 my ($self, $dir, $rpm, $wrong_rpm) = @_;
578 my $run = $self->{run};
579 my $cache = $run->{cache};
580 my ($arch) = $rpm =~ /([^\.]+)\.rpm$/ or return 0;
581 my $srpm = $cache->{rpm_srpm}{$rpm};
582 if (!$srpm) {
583 my $hdr = RPM4::Header->new("$dir/$rpm");
584 $hdr or return 0;
585 $srpm = $hdr->queryformat('%{SOURCERPM}');
586 $cache->{rpm_srpm}{$rpm} = $srpm;
587 }
588 $srpm = fix_srpm_name($cache, $srpm, $rpm, $wrong_rpm);
589 $arch, $srpm;
590 }
591
592 sub fix_srpm_name {
593 my ($cache, $srpm, $rpm, $wrong_rpm) = @_;
594 my $old_srpm = $srpm;
595 if ($srpm =~ s/^lib64/lib/) {
596 push @$wrong_rpm, [ $old_srpm, $rpm ] if ref $wrong_rpm;
597 $cache->{rpm_srpm}{$rpm} = $srpm;
598 }
599 $srpm;
600 }
601
602 sub recreate_srpm {
603 my ($_self, $run, $config, $chroot_tmp, $dir, $srpm, $luser, $b_retry) = @_;
604 # recreate a new srpm for buildarch condition in the spec file
605 my $program_name = $run->{program_name};
606 my $cache = $run->{cache};
607 my $with_flags = $run->{with_flags};
608
609 plog('NOTIFY', "recreate srpm: $srpm");
610
611 perform_command([
612 sub {
613 my ($s, $d) = @_;
614 sudo($run, $config, '--cp', $s, $d) } , [ "$dir/$srpm", "$chroot_tmp/home/$luser/rpm/SRPMS/" ] ],
615 $run, $config, $cache,
616 type => 'perl',
617 mail => $config->{admin},
618 error => "[REBUILD] cannot copy $srpm to $chroot_tmp",
619 debug_mail => $run->{debug},
620 hash => "copy_$srpm") or return;
621
622 my %opt = (mail => $config->{admin},
623 error => "[REBUILD] cannot install $srpm in $chroot_tmp",
624 use_iurt_root_command => 1,
625 debug_mail => $run->{debug},
626 hash => "install_$srpm",
627 retry => $b_retry,
628 callback => sub {
629 my ($opt, $output) = @_;
630 plog('DEBUG', "calling callback for $opt->{hash}");
631 if ($output =~ /warning: (group|user) .* does not exist - using root|Header V3 DSA signature/i) {
632 return 1;
633 } elsif ($output =~ /user $luser does not exist|cannot write to \%sourcedir/) {
634 plog('WARN', "WARNING: chroot seems corrupted!");
635 $opt->{error} = "[CHROOT] chroot is corrupted";
636 $opt->{retry} ||= 1;
637 return;
638 }
639 1;
640 });
641 plog('DEBUG', "recreating src.rpm...");
642 if (!perform_command(qq(chroot $chroot_tmp su $luser -c "rpm -i /home/$luser/rpm/SRPMS/$srpm"),
643 $run, $config, $cache, %opt)) {
644 plog("ERROR: chrooting failed (retry $opt{retry}") if $run->{debug};
645 if ($opt{retry}) {
646 check_build_chroot($run->{chroot_path}, $run->{chroot_tar}, $run, $config) or return;
647 return -1;
648 }
649 return;
650 }
651
652 my $spec;
653 my $oldsrpm = "$chroot_tmp/home/$luser/rpm/SRPMS/$srpm";
654 my $filelist = `rpm -qlp $oldsrpm`;
655 my ($name) = $srpm =~ /(?:.*:)?(.*)-[^-]+-[^-]+\.src\.rpm$/;
656 foreach my $file (split "\n", $filelist) {
657 if ($file =~ /(.*)\.spec/) {
658 if (!$spec) {
659 $spec = $file;
660 } elsif ($1 eq $name) {
661 $spec = $file;
662 }
663 }
664 }
665 # 20060515 This should not be necessairy any more if urpmi *.spec works, but it doesn't
666 #
667 my $ret = perform_command(qq(chroot $chroot_tmp su $luser -c "rpmbuild --nodeps -bs $with_flags /home/$luser/rpm/SPECS/$spec"),
668 $run, $config, $cache,
669 use_iurt_root_command => 1,
670 mail => $config->{admin},
671 error => "[REBUILD] cannot create $srpm in $chroot_tmp",
672 debug_mail => $run->{debug},
673 hash => "create_$srpm"
674 );
675
676 # Return if we can't regenerate srpm
677 #
678 return (0, ,) unless $ret;
679
680 # CM: was: foreach my $file (readdir $dir)
681 # The above line returned entries in a strange order in my test
682 # system, such as
683 # ..
684 # cowsay-3.03-11mdv2007.1.src.rpm
685 # cowsay-3.03-11mdv2007.0.src.rpm
686 # .
687 # assigning '.' to $new_rpm. Now sorting the output.
688
689 # we can not ask rpm the generated srpm name
690 # we can not rely on build time (one of the src.rpm may have been built on a machine with wrong time)
691 # let's say that if we have several one, we want the non original one
692 my $file = $oldsrpm;
693 foreach my $f (glob "$chroot_tmp/home/$luser/rpm/SRPMS/$name-*.src.rpm") {
694 $file = $f if $f ne $oldsrpm;
695 }
696 my ($new_srpm) = basename($file);
697 my $prefix = get_package_prefix($srpm);
698 my $newfile = "$chroot_tmp/home/$luser/rpm/SRPMS/$prefix$new_srpm";
699 if (-f $file && $newfile ne $file) {
700 if (-f $newfile) {
701 sudo($run, $config, '--rm', $newfile) or die "$program_name: could not delete $newfile ($!)";
702 }
703 sudo($run, $config, '--ln', $file, $newfile) or die "$program_name: linking $file to $newfile failed ($!)";
704 unlink $file;
705 unlink $oldsrpm if $oldsrpm ne $newfile;
706 }
707 plog('NOTIFY', "new srpm: $prefix$new_srpm");
708 ($ret, "$prefix$new_srpm", $spec);
709 }
710
711 1;

  ViewVC Help
Powered by ViewVC 1.1.30