ErrorList.pm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # ex:ts=8 sw=4:
  2. # $OpenBSD: ErrorList.pm,v 1.4 2015/06/22 12:18:19 espie Exp $
  3. #
  4. # Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
  5. #
  6. # Permission to use, copy, modify, and distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. use strict;
  18. use warnings;
  19. # Abstract interface to problems that must be handled asynchronously
  20. # the base class manages a list of issues, and has a basic "recheck"
  21. # call (template method pattern) that will be specialized.
  22. package DPB::ErrorList::Base;
  23. sub new
  24. {
  25. my $class = shift;
  26. bless [], $class;
  27. }
  28. sub recheck
  29. {
  30. my ($list, $engine) = @_;
  31. return if @$list == 0;
  32. my $locker = $engine->{locker};
  33. my @keep = ();
  34. while (my $v = shift @$list) {
  35. if ($list->unlock_early($v, $engine)) {
  36. $locker->unlock($v);
  37. next;
  38. }
  39. if ($locker->locked($v)) {
  40. push(@keep, $v);
  41. } else {
  42. $list->reprepare($v, $engine);
  43. }
  44. }
  45. push(@$list, @keep) if @keep != 0;
  46. }
  47. sub stringize
  48. {
  49. my $list = shift;
  50. my @l = ();
  51. for my $e (@$list) {
  52. my $s = $e->logname;
  53. if (defined $e->{host} && !$e->{host}->is_localhost) {
  54. $s .= "(".$e->{host}->name.")";
  55. }
  56. if (defined $e->{info} && $e->{info}->has_property('nojunk')) {
  57. $s .= '!';
  58. }
  59. push(@l, $s);
  60. }
  61. return join(' ', @l);
  62. }
  63. sub reprepare
  64. {
  65. my ($class, $v, $engine) = @_;
  66. $v->requeue($engine);
  67. }
  68. # actual errors, if the user removes the lock, then rescan and requeue
  69. package DPB::ErrorList;
  70. our @ISA = (qw(DPB::ErrorList::Base));
  71. sub unlock_early
  72. {
  73. my ($list, $v, $engine) = @_;
  74. if ($v->unlock_conditions($engine)) {
  75. $v->requeue($engine);
  76. return 1;
  77. } else {
  78. return 0;
  79. }
  80. }
  81. sub reprepare
  82. {
  83. my ($list, $v, $engine) = @_;
  84. $engine->rescan($v);
  85. }
  86. # locks: stuff that can't be built because something else with an almost
  87. # identical path is building.
  88. package DPB::LockList;
  89. our @ISA = (qw(DPB::ErrorList::Base));
  90. sub unlock_early
  91. {
  92. &DPB::ErrorList::unlock_early;
  93. }
  94. sub stringize
  95. {
  96. my $list = shift;
  97. my @l = ();
  98. my $done = {};
  99. for my $e (@$list) {
  100. my $s = $e->lockname;
  101. if (!defined $done->{$s}) {
  102. push(@l, $s);
  103. $done->{$s} = 1;
  104. }
  105. }
  106. return join(' ', @l);
  107. }
  108. # NFS overload handling. Doesn't appear that often these days
  109. # at the end of a succesful build, the packages might not show up
  110. # directly. So keep them around
  111. package DPB::NFSList;
  112. our @ISA = (qw(DPB::ErrorList::Base));
  113. sub reprepare
  114. {
  115. &DPB::ErrorList::reprepare;
  116. }
  117. sub unlock_early
  118. {
  119. my ($list, $v, $engine) = @_;
  120. my $okay = 1;
  121. my $sub = $engine->{buildable};
  122. my $h = $sub->{nfs}{$v};
  123. while (my ($k, $w) = each %$h) {
  124. if ($sub->remove_stub($w)) {
  125. delete $h->{$k};
  126. } elsif ($sub->{builder}->end_check($w)) {
  127. $sub->mark_as_done($w);
  128. delete $h->{$k};
  129. } else {
  130. $okay = 0;
  131. # infamous: this is the case where the server is late
  132. # seeing the files
  133. $engine->log('H', $w);
  134. }
  135. }
  136. if ($okay) {
  137. delete $sub->{nfs}{$v};
  138. }
  139. return $okay;
  140. }
  141. 1;