/usr/lib/obs/server/bs_publish is in obs-server 2.7.4-2.
This file is owned by root:root, with mode 0o755.
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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 | #!/usr/bin/perl -w
#
# Copyright (c) 2006, 2007 Michael Schroeder, Novell Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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 (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
#
# The Publisher. Create repositories and push them to our mirrors.
#
BEGIN {
my ($wd) = $0 =~ m-(.*)/- ;
$wd ||= '.';
unshift @INC, "$wd/build";
unshift @INC, "$wd";
}
use Digest;
use Digest::MD5 ();
use Digest::SHA ();
use XML::Structured ':bytes';
use XML::Simple ();
use POSIX;
use Fcntl qw(:DEFAULT :flock);
use Data::Dumper;
use Storable ();
use MIME::Base64;
use BSConfiguration;
use BSRPC;
use BSUtil;
use BSDBIndex;
use Build;
use BSDB;
use BSXML;
use BSNotify;
use BSVerify;
use strict;
BSUtil::drop_privs_to($BSConfig::bsuser||$BSConfig::bsuser, $BSConfig::bsgroup||$BSConfig::bsgroup);
BSUtil::set_fdatasync_before_rename() unless $BSConfig::disable_data_sync || $BSConfig::disable_data_sync;
my $reporoot = "$BSConfig::bsdir/build";
my $eventdir = "$BSConfig::bsdir/events";
my $extrepodir = "$BSConfig::bsdir/repos";
my $extrepodir_sync = "$BSConfig::bsdir/repos_sync";
my $uploaddir = "$BSConfig::bsdir/upload";
my $rundir = $BSConfig::rundir || "$BSConfig::bsdir/run";
my $extrepodb = "$BSConfig::bsdir/db/published";
my $myeventdir = "$eventdir/publish";
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz};
my $binsufsre = join('|', map {"\Q$_\E"} @binsufs);
my @binsufsrsync = map {"--include=*.$_"} @binsufs;
my $testmode;
sub qsystem {
my @args = @_;
my $pid;
local (*RH, *WH);
if ($args[0] eq 'echo') {
pipe(RH, WH) || die("pipe: $!\n");
}
if (!($pid = xfork())) {
if ($args[0] eq 'echo') {
close WH;
open(STDIN, "<&RH");
close RH;
splice(@args, 0, 2);
}
open(STDOUT, ">/dev/null");
if ($args[0] eq 'chdir') {
chdir($args[1]) || die("chdir $args[1]: $!\n");
splice(@args, 0, 2);
}
if ($args[0] eq 'stdout') {
open(STDOUT, '>', $args[1]) || die("$args[1]: $!\n");
splice(@args, 0, 2);
}
eval {
exec(@args);
die("$args[0]: $!\n");
};
warn($@) if $@;
exit 1;
}
if ($args[0] eq 'echo') {
close RH;
print WH $args[1];
close WH;
}
waitpid($pid, 0) == $pid || die("waitpid $pid: $!\n");
return $?;
}
sub fillpkgdescription {
my ($pkg, $extrep, $repoinfo, $name) = @_;
my $binaryorigins = $repoinfo->{'binaryorigins'} || {};
my $hit;
for my $p (sort keys %$binaryorigins) {
next if $p =~ /src\.rpm$/;
next unless $p =~ /\/\Q$name\E/;
my ($pa, $pn) = split('/', $p, 2);
if ($pn =~ /^\Q$name\E-([^-]+-[^-]+)\.[^\.]+\.rpm$/) {
$hit = $p;
last;
}
if ($pn =~ /^\Q$name\E_([^_]+)_[^_]+\.deb$/) {
$hit = $p;
last;
}
}
return unless $hit;
my $data = Build::query("$extrep/$hit", 'description' => 1);
$pkg->{'description'} = str2utf8($data->{'description'});
$pkg->{'summary'} = str2utf8($data->{'summary'}) if defined $data->{'summary'};
}
############################################################################################
my @db_sync;
my $db_oldsync_read;
sub db_open {
my ($name) = @_;
return undef unless $extrepodb;
if (!$db_oldsync_read) {
if (-s "$extrepodb.sync") {
my $oldsync = BSUtil::retrieve("$extrepodb.sync");
@db_sync = @{$oldsync || []};
}
$db_oldsync_read = 1;
}
return {'name' => $name, 'index' => "$name/"};
}
sub db_updateindex_rel {
my ($db, $rem, $add) = @_;
push @db_sync, $db->{'name'}, $rem, $add;
}
sub db_store {
my ($db, $k, $v) = @_;
push @db_sync, $db->{'name'}, $k, $v;
}
sub db_sync {
return undef unless $extrepodb;
db_open('') unless $db_oldsync_read;
return unless @db_sync;
my $data = Storable::nfreeze(\@db_sync);
my $ops = @db_sync;
for (@db_sync) {
$ops += @$_ if $_ && ref($_) eq 'ARRAY';
}
my $timeout = $ops / 30;
$timeout = 60 if $timeout < 60;
my $param = {
'uri' => "$BSConfig::srcserver/search/published",
'request' => 'POST',
'maxredirects' => 3,
'timeout' => $timeout,
'headers' => [ 'Content-Type: application/octet-stream' ],
'data' => $data,
};
print " syncing database ($ops ops)\n";
eval {
BSRPC::rpc($param, undef, 'cmd=updatedb');
};
if ($@) {
warn($@);
mkdir_p($1) if $extrepodb =~ /^(.*)\//;
BSUtil::store("$extrepodb.sync.new", "$extrepodb.sync", \@db_sync);
} else {
@db_sync = ();
unlink("$extrepodb.sync");
}
}
############################################################################################
sub updatebinaryindex {
my ($db, $keyrem, $keyadd) = @_;
my $index = $db->{'index'};
$index =~ s/\/$//;
my @add;
for my $key (@{$keyadd || []}) {
my $n;
if ($key =~ /(?:^|\/)([^\/]+)-[^-]+-[^-]+\.[a-zA-Z][^\/\.\-]*\.rpm$/) {
$n = $1;
} elsif ($key =~ /(?:^|\/)([^\/]+)_([^\/]*)_[^\/]*\.deb$/) {
$n = $1;
} elsif ($key =~ /(?:^|\/)([^\/]+)-[^-]+-[^-]+-[a-zA-Z][^\/\.\-]*\.pkg\.tar\..z$/) {
$n = $1;
} else {
next;
}
push @add, ["$index/name", $n, $key];
}
my @rem;
for my $key (@{$keyrem || []}) {
my $n;
if ($key =~ /(?:^|\/)([^\/]+)-[^-]+-[^-]+\.[a-zA-Z][^\/\.\-]*\.rpm$/) {
$n = $1;
} elsif ($key =~ /(?:^|\/)([^\/]+)_([^\/]*)_[^\/]*\.deb$/) {
$n = $1;
} elsif ($key =~ /(?:^|\/)([^\/]+)-[^-]+-[^-]+-[a-zA-Z][^\/\.\-]*\.pkg\.tar\..z$/) {
$n = $1;
} else {
next;
}
push @rem, ["$index/name", $n, $key];
}
db_updateindex_rel($db, \@rem, \@add);
}
##########################################################################
sub getpatterns {
my ($projid) = @_;
my $dir;
eval {
$dir = BSRPC::rpc("$BSConfig::srcserver/source/$projid/_pattern", $BSXML::dir);
};
if ($@) {
warn($@);
return [];
}
my @ret;
my @args;
push @args, "rev=$dir->{'srcmd5'}" if $dir->{'srcmd5'} && $dir->{'srcmd5'} ne 'pattern';
for my $entry (@{$dir->{'entry'} || []}) {
my $pat;
eval {
$pat = BSRPC::rpc("$BSConfig::srcserver/source/$projid/_pattern/$entry->{'name'}", undef, @args);
# only patterns we can parse, please
BSUtil::fromxml($pat, $BSXML::pattern);
};
if ($@) {
warn(" pattern $entry->{'name'}: $@");
next;
}
push @ret, {'name' => $entry->{'name'}, 'md5' => $entry->{'md5'}, 'data' => $pat};
}
print " fetched ".@ret." patterns\n";
return \@ret;
}
##########################################################################
sub addsizechecksum {
my ($filename, $d, $sum) = @_;
local *F;
open(F, '<', $filename) || return;
$d->{'size'} = -s F;
my %known = (
'sha' => 'SHA-1',
'sha1' => 'SHA-1',
'sha256' => 'SHA-256',
);
if ($known{$sum}) {
my $ctx = Digest->new($known{$sum});
$ctx->addfile(\*F);
$d->{'checksum'} = {'type' => $sum, '_content' => $ctx->hexdigest()};
}
close F;
}
sub create_appdata_files {
my ($dir, $appdatas) = @_;
$appdatas = Storable::dclone($appdatas);
print " creating appdata files\n";
my %ids;
my %written;
mkdir_p("$dir/app-icons");
for my $app (@{$appdatas->{'application'} || []}, @{$appdatas->{'component'} || []}) {
for my $icon (@{$app->{'icon'} || []}) {
my $iconname = ($icon->{'name'} || [])->[0];
my $filecontent = ($icon->{'filecontent'} || [])->[0];
next unless $iconname && $icon->{'filecontent'};
next if $iconname =~ /\//s;
my %files;
for my $filecontent (@{$icon->{'filecontent'}}) {
if (ref($filecontent)) {
next unless $filecontent->{'content'};
$files{$filecontent->{'file'} || $iconname} ||= $filecontent->{'content'};
} else {
$files{$iconname} ||= $filecontent if $filecontent;
}
}
next unless %files;
my $fn;
for my $size (qw(32 48 64 24)) {
my @c = grep {/${size}x$size/} sort(keys %files);
my @ch = grep {/\/hicolor\//} @c;
@c = @ch if @ch;
$fn = $c[0];
last if $fn;
}
$fn ||= (sort(keys %files))[0];
if ($iconname !~ /\./) {
next unless $fn =~ /(\.[^\.\/]+)$/;
$iconname .= $1;
}
if (!$written{$iconname}) {
writestr("$dir/app-icons/$iconname", undef, decode_base64($files{$fn}));
$written{$iconname} = 1;
}
$icon = { 'type' => 'cached', 'content' => $iconname};
}
}
unlink("$dir/app-icons.tar");
if (%written) {
qsystem('chdir', "$dir/app-icons", 'tar', 'cf', '../app-icons.tar', '.') && die(" app-icons tar failed: $?\n");
BSUtil::cleandir("$dir/app-icons");
}
rmdir("$dir/app-icons");
$appdatas->{'version'} ||= '0.6';
my $rootname = @{$appdatas->{'application'} || []} ? 'applications' : 'components';
my $appdatasxml = XML::Simple::XMLout($appdatas, 'RootName' => $rootname, XMLDecl => '<?xml version="1.0" encoding="UTF-8"?>');
Encode::_utf8_off($appdatasxml);
writestr("$dir/appdata.xml", undef, $appdatasxml);
}
sub createrepo_rpmmd {
my ($extrep, $projid, $repoid, $data, $options) = @_;
my %options = map {$_ => 1} @{$options || []};
my @repotags = @{$data->{'repotags'} || []};
my $prp_ext = "$projid/$repoid";
$prp_ext =~ s/:/:\//g;
print " running createrepo\n";
# cleanup files
unlink("$extrep/repodata/repomd.xml.asc");
unlink("$extrep/repodata/repomd.xml.key");
unlink("$extrep/repodata/latest-feed.xml");
unlink("$extrep/repodata/index.html");
my @oldrepodata = ls("$extrep/repodata");
qsystem('rm', '-rf', "$extrep/repodata/repoview") if -d "$extrep/repodata/repoview";
qsystem('rm', '-rf', "$extrep/repodata/.olddata") if -d "$extrep/repodata/.olddata";
qsystem('rm', '-f', "$extrep/repodata/patterns*");
# create generic rpm-md meta data
# --update requires a newer createrepo version, tested with version 0.4.10
my @createrepoargs;
push @createrepoargs, '--changelog-limit', '20';
push @createrepoargs, map { ('--repo', $_ ) } @repotags;
push @createrepoargs, '--content', 'debug' if $data->{'dbgsplit'};
my @legacyargs;
if ($options{'legacy'}) {
push @legacyargs, '--simple-md-filenames', '--checksum=sha';
} else {
# the default in newer createrepos
push @legacyargs, '--unique-md-filenames', '--checksum=sha256';
}
my @updateargs;
# createrepo 0.9.9 defaults to creating the sqlite database.
# We do disable it since it is time and space consuming.
# doing this via @updateargs for the case that an old createrepo is installed which does not support
# this switch.
push @updateargs, '--no-database';
if (-f "$extrep/repodata/repomd.xml") {
push @updateargs, '--update';
}
if (qsystem('createrepo', '-q', '-c', "$extrep/repocache", @updateargs, @createrepoargs, @legacyargs, $extrep)) {
die(" createrepo failed: $?\n") unless @updateargs;
print(" createrepo failed: $?\n");
print " re-running without extra options\n";
qsystem('createrepo', '-q', '-c', "$extrep/repocache", @createrepoargs, @legacyargs, $extrep) && die(" createrepo failed again: $?\n");
}
unlink("$extrep/repodata/$_") for grep {/updateinfo\.xml/} @oldrepodata;
if (@{$data->{'updateinfos'} || []}) {
print " adding updateinfo.xml to repodata\n";
# strip supportstatus and patchinforef from updateinfos
my $updateinfos = Storable::dclone($data->{'updateinfos'});
for my $up (@$updateinfos) {
delete $up->{'patchinforef'};
for my $cl (@{($up->{'pkglist'} || {})->{'collection'} || []}) {
delete $_->{'supportstatus'} for @{$cl->{'package'} || []};
}
}
writexml("$extrep/repodata/updateinfo.xml", undef, {'update' => $updateinfos}, $BSXML::updateinfo);
qsystem('modifyrepo', "$extrep/repodata/updateinfo.xml", "$extrep/repodata", @legacyargs) && die(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/updateinfo.xml");
}
unlink("$extrep/repodata/$_") for grep {/appdata\.xml/ || /app-icons/} @oldrepodata;
if (%{$data->{'appdatas'} || {}}) {
create_appdata_files("$extrep/repodata", $data->{'appdatas'});
if (-e "$extrep/repodata/appdata.xml") {
print " adding appdata.xml to repodata\n";
qsystem('modifyrepo', "$extrep/repodata/appdata.xml", "$extrep/repodata", @legacyargs) && die(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/appdata.xml");
}
if (-e "$extrep/repodata/app-icons.tar") {
print " adding app-icons.tar to repodata\n";
qsystem('modifyrepo', "$extrep/repodata/app-icons.tar", "$extrep/repodata", @legacyargs) && die(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/app-icons.tar");
}
}
unlink("$extrep/repodata/$_") for grep {/(?:deltainfo|prestodelta)\.xml/} @oldrepodata;
if (%{$data->{'deltainfos'} || {}} && ($options{'deltainfo'} || $options{'prestodelta'})) {
print " adding deltainfo.xml to repodata\n" if $options{'deltainfo'};
print " adding prestodelta.xml to repodata\n" if $options{'prestodelta'};
# things are a bit complex, as we have to merge the deltas, and we also have to add the checksum
my %mergeddeltas;
for my $d (values(%{$data->{'deltainfos'}})) {
addsizechecksum("$extrep/$d->{'delta'}->[0]->{'filename'}", $d->{'delta'}->[0], $options{'legacy'} ? 'sha' : 'sha256');
my $mkey = "$d->{'arch'}\0$d->{'name'}\0$d->{'epoch'}\0$d->{'version'}\0$d->{'release'}\0";
if ($mergeddeltas{$mkey}) {
push @{$mergeddeltas{$mkey}->{'delta'}}, $d->{'delta'}->[0];
} else {
$mergeddeltas{$mkey} = $d;
}
}
# got all, now write
my @mergeddeltas = map {$mergeddeltas{$_}} sort keys %mergeddeltas;
if ($options{'deltainfo'}) {
writexml("$extrep/repodata/deltainfo.xml", undef, {'newpackage' => \@mergeddeltas}, $BSXML::deltainfo);
qsystem('modifyrepo', "$extrep/repodata/deltainfo.xml", "$extrep/repodata", @legacyargs) && die(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/deltainfo.xml");
}
if ($options{'prestodelta'}) {
writexml("$extrep/repodata/prestodelta.xml", undef, {'newpackage' => \@mergeddeltas}, $BSXML::prestodelta);
qsystem('modifyrepo', "$extrep/repodata/prestodelta.xml", "$extrep/repodata", @legacyargs) && die(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/prestodelta.xml");
}
}
if (-d "$extrep/repocache") {
my $now = time;
for (map { "$extrep/repocache/$_" } ls("$extrep/repocache")) {
my @s = stat($_);
unlink($_) if @s && $s[9] < $now - 7*86400;
}
}
my $title = $data->{'repoinfo'}->{'title'};
my $downloadurl = get_downloadurl("$projid/$repoid", $prp_ext);
if (-x "/usr/bin/repoview") {
my @downloadurlarg;
@downloadurlarg = ("-u$downloadurl") if $downloadurl;
print " running repoview\n";
qsystem('repoview', '-f', @downloadurlarg, "-t$title", $extrep) && print(" repoview failed: $?\n");
}
if ($BSConfig::createrepo_rpmmd_hook) {
$BSConfig::createrepo_rpmmd_hook->($projid, $repoid, $extrep, \%options, $data);
}
if ($options{'rsyncable'}) {
if (-x '/usr/bin/rezip_repo_rsyncable') {
print " re-compressing metadata with --rsyncable\n";
unlink("$extrep/repodata/repomd.xml.asc");
qsystem('/usr/bin/rezip_repo_rsyncable', $extrep) && print(" rezip_repo_rsyncable failed: $?\n");
} else {
print " /usr/bin/rezip_repo_rsyncable not installed, ignoring the rsyncable option\n";
}
}
if ($BSConfig::sign && -e "$extrep/repodata/repomd.xml") {
my @signargs;
push @signargs, '--project', $projid if $BSConfig::sign_project;
push @signargs, @{$data->{'signargs'} || []};
qsystem($BSConfig::sign, @signargs, '-d', "$extrep/repodata/repomd.xml") && die(" sign failed: $?\n");
writestr("$extrep/repodata/repomd.xml.key", undef, $data->{'pubkey'}) if $data->{'pubkey'};
}
if ($downloadurl) {
local *FILE;
open(FILE, '>', "$extrep/$projid.repo$$") || die("$extrep/$projid.repo$$: $!\n");
my $projidHeader = $projid;
$projidHeader =~ s/:/_/g;
print FILE "[$projidHeader]\n";
print FILE "name=$title\n";
print FILE "type=rpm-md\n";
print FILE "baseurl=$downloadurl\n";
if ($BSConfig::sign) {
print FILE "gpgcheck=1\n";
if (-e "$extrep/repodata/repomd.xml.key") {
print FILE "gpgkey=$downloadurl/repodata/repomd.xml.key\n";
} else {
die("neither a project key is available nor gpg_standard_key is set\n") unless defined($BSConfig::gpg_standard_key);
print FILE "gpgkey=$BSConfig::gpg_standard_key\n";
}
}
print FILE "enabled=1\n";
close(FILE) || die("close: $!\n");
rename("$extrep/$projid.repo$$", "$extrep/$projid.repo") || die("rename $extrep/$projid.repo$$ $extrep/$projid.repo: $!\n");
}
}
sub deleterepo_rpmmd {
my ($extrep, $projid) = @_;
qsystem('rm', '-rf', "$extrep/repodata") if -d "$extrep/repodata";
unlink("$extrep/$projid.repo");
}
sub createrepo_virtbuilder {
my ($extrep, $projid, $repoid, $data) = @_;
# cleanup
unlink("$extrep/index.key");
unlink("$extrep/index.asc");
# Sign the index
if ($BSConfig::sign && -e "$extrep/index") {
my @signargs;
print "Signing the index for $projid/$repoid\n";
push @signargs, '--project', $projid if $BSConfig::sign_project;
push @signargs, @{$data->{'signargs'} || []};
print "Running command: $BSConfig::sign @signargs -c $extrep/index\n";
qsystem($BSConfig::sign, @signargs, '-c', "$extrep/index") && die(" sign failed: $?\n");
writestr("$extrep/index.key", undef, $data->{'pubkey'}) if $data->{'pubkey'};
}
}
sub createrepo_hdlist2 {
my ($extrep, $projid, $repoid, $data, $options) = @_;
print " running hdlist2\n";
# create generic rpm-md meta data
for my $arch (ls($extrep)) {
next if $arch =~ /^\./;
my $r = "$extrep/$arch";
next unless -d $r;
if (qsystem('genhdlist2', '--allow-empty-media', $r)) {
print(" genhdlist2 failed: $?\n");
}
}
# signing is done only via rpm packages to my information
}
sub deleterepo_hdlist2 {
my ($extrep, $projid) = @_;
for my $arch (ls($extrep)) {
next if $arch =~ /^\./;
my $r = "$extrep/$arch";
next unless -d $r;
qsystem('rm', '-rf', "$r/media_info") if -d "$r/media_info";
}
}
sub createrepo_susetags {
my ($extrep, $projid, $repoid, $data, $options) = @_;
mkdir_p("$extrep/media.1");
mkdir_p("$extrep/descr");
my @lt = localtime(time());
$lt[4] += 1;
$lt[5] += 1900;
my $str = sprintf("Open Build Service\n%04d%02d%02d%02d%02d%02d\n1\n", @lt[5,4,3,2,1,0]);
writestr("$extrep/media.1/.media", "$extrep/media.1/media", $str);
writestr("$extrep/media.1/.directory.yast", "$extrep/media.1/directory.yast", "media\n");
$str = <<"EOL";
PRODUCT Open Build Service $projid $repoid
VERSION 1.0-0
LABEL $data->{'repoinfo'}->{'title'}
VENDOR Open Build Service
ARCH.x86_64 x86_64 i686 i586 i486 i386 noarch
ARCH.k1om k1om noarch
ARCH.ppc64p7 ppc64p7 noarch
ARCH.ppc64 ppc64 ppc noarch
ARCH.ppc64le ppc64le noarch
ARCH.ppc ppc noarch
ARCH.sh4 sh4 noarch
ARCH.m68k m68k noarch
ARCH.aarch64 aarch64 aarch64_ilp32 noarch
ARCH.aarch64_ilp32 aarch64_ilp32 noarch
ARCH.armv4l arm armv4l noarch
ARCH.armv5l arm armel armv4l armv5l armv5tel noarch
ARCH.armv6l arm armel armv4l armv5l armv5tel armv6l armv6vl armv6hl noarch
ARCH.armv7l arm armel armv4l armv5l armv5tel armv6l armv6vl armv7l armv7hl noarch
ARCH.i686 i686 i586 i486 i386 noarch
ARCH.i586 i586 i486 i386 noarch
DEFAULTBASE i586
DESCRDIR descr
DATADIR .
EOL
writestr("$extrep/.content", "$extrep/content", $str);
print " running create_package_descr\n";
qsystem('chdir', $extrep, 'create_package_descr', '-o', 'descr', '-x', '/dev/null') && print " create_package_descr failed: $?\n";
unlink("$extrep/descr/directory.yast");
my @d = map {"$_\n"} sort(ls("$extrep/descr"));
writestr("$extrep/descr/.directory.yast", "$extrep/descr/directory.yast", join('', @d));
}
sub deleterepo_susetags {
my ($extrep) = @_;
unlink("$extrep/directory.yast");
unlink("$extrep/content");
unlink("$extrep/media.1/media");
unlink("$extrep/media.1/directory.yast");
rmdir("$extrep/media.1");
qsystem('rm', '-rf', "$extrep/descr") if -d "$extrep/descr";
}
sub createrepo_debian {
my ($extrep, $projid, $repoid, $data, $options) = @_;
print " running dpkg-scanpackages\n";
if (qsystem('chdir', $extrep, 'stdout', 'Packages.new', 'dpkg-scanpackages', '-m', '.', '/dev/null')) {
die(" dpkg-scanpackages failed: $?\n");
}
if (-f "$extrep/Packages.new") {
unlink("$extrep/Packages");
link("$extrep/Packages.new", "$extrep/Packages");
qsystem('gzip', '-9', '-n', '-f', "$extrep/Packages.new") && print " gzip Packages.new failed: $?\n";
unlink("$extrep/Packages.new");
unlink("$extrep/Packages.gz");
rename("$extrep/Packages.new.gz", "$extrep/Packages.gz");
} else {
unlink("$extrep/Packages");
unlink("$extrep/Packages.gz");
}
print " running dpkg-scansources\n";
if (qsystem('chdir', $extrep, 'stdout', 'Sources.new', 'dpkg-scansources', '.', '/dev/null')) {
die(" dpkg-scansources failed: $?\n");
}
if (-f "$extrep/Sources.new") {
unlink("$extrep/Sources");
link("$extrep/Sources.new", "$extrep/Sources");
qsystem('gzip', '-9', '-n', '-f', "$extrep/Sources.new") && print " gzip Sources.new failed: $?\n";
unlink("$extrep/Sources.new");
unlink("$extrep/Sources.gz");
rename("$extrep/Sources.new.gz", "$extrep/Sources.gz");
} else {
unlink("$extrep/Sources");
unlink("$extrep/Sources.gz");
}
my $obsname = $BSConfig::obsname || 'build.opensuse.org';
my $date = POSIX::ctime(time());
$date =~ s/\n//m;
my @debarchs = @{$data->{'repoinfo'}->{'arch'} || []};
for (@debarchs) {
s/x86_64/amd64/g;
s/i.86/i386/g;
s/ppc64le/ppc64el/g;
};
my $archs = join(' ', @debarchs);
# The Release file enables users to use Pinning. See also:
# http://www.debian.org/doc/manuals/repository-howto/repository-howto#release
# apt_preferences(5)
#
# Note:
# There is no Version because this is not part of a Debian release (yet).
# The Component line is missing to not accidently associate the packages with
# a Debian licensing component.
my $str = <<"EOL";
Archive: $repoid
Codename: $repoid
Origin: obs://$obsname/$projid/$repoid
Label: $projid
Architectures: $archs
Date: $date
Description: $data->{'repoinfo'}->{'title'}
MD5Sum:
EOL
open(OUT, '>', "$extrep/Release") || die("$extrep/Release: $!\n");
print OUT $str;
close(OUT) || die("close: $!\n");
# append checksums
my $sha1sums = "SHA1:\n";
my $sha256sums = "SHA256:\n";
open(OUT, '>>', "$extrep/Release") || die("$extrep/Release: $!\n");
for my $f ( "Packages", "Packages.gz", "Sources", "Sources.gz" ) {
my @s = stat("$extrep/$f");
next unless @s;
my $fdata = readstr("$extrep/$f");
my $md5 = Digest::MD5::md5_hex($fdata);
my $size = $s[7];
print OUT " $md5 $size $f\n";
my $sha1 = Digest::SHA::sha1_hex($fdata);
$sha1sums .= " $sha1 $size $f\n";
my $sha256 = Digest::SHA::sha256_hex($fdata);
$sha256sums .= " $sha256 $size $f\n";
}
print OUT $sha1sums;
print OUT $sha256sums;
close(OUT) || die("close: $!\n");
unlink("$extrep/Release.gpg");
unlink("$extrep/Release.key");
# re-sign changed Release file
if ($BSConfig::sign && -e "$extrep/Release") {
my @signargs;
push @signargs, '--project', $projid if $BSConfig::sign_project;
push @signargs, @{$data->{'signargs'} || []};
qsystem($BSConfig::sign, @signargs, '-d', "$extrep/Release") && die(" sign failed: $?\n");
rename("$extrep/Release.asc","$extrep/Release.gpg");
}
if ($BSConfig::sign) {
writestr("$extrep/Release.key", undef, $data->{'pubkey'}) if $data->{'pubkey'};
}
}
sub deleterepo_debian {
my ($extrep) = @_;
unlink("$extrep/Packages");
unlink("$extrep/Packages.gz");
unlink("$extrep/Sources");
unlink("$extrep/Sources.gz");
unlink("$extrep/Release");
unlink("$extrep/Release.gpg");
unlink("$extrep/Release.key");
}
##########################################################################
sub createrepo_arch {
my ($extrep, $projid, $repoid, $data, $options) = @_;
deleterepo_arch($extrep);
my $rname = $projid;
$rname .= "_$repoid" if $repoid ne 'standard';
$rname =~ s/:/_/g;
for my $arch (ls($extrep)) {
next unless -d "$extrep/$arch";
print " running bs_mkarchrepo $arch\n";
qsystem("$INC[0]/bs_mkarchrepo", $rname, "$extrep/$arch") && die(" repo creation failed: $?\n");
if (-e "$extrep/$arch/$rname.db.tar.gz") {
link("$extrep/$arch/$rname.db.tar.gz", "$extrep/$arch/$rname.db");
}
if (-e "$extrep/$arch/$rname.files.tar.gz") {
link("$extrep/$arch/$rname.files.tar.gz", "$extrep/$arch/$rname.files");
}
if ($BSConfig::sign) {
my @signargs;
push @signargs, '--project', $projid if $BSConfig::sign_project;
push @signargs, @{$data->{'signargs'} || []};
if (-e "$extrep/$arch/$rname.db.tar.gz") {
qsystem($BSConfig::sign, @signargs, '-D', "$extrep/$arch/$rname.db.tar.gz") && die(" sign failed: $?\n");
link("$extrep/$arch/$rname.db.tar.gz.sig", "$extrep/$arch/$rname.db.sig");
}
if (-e "$extrep/$arch/$rname.files.tar.gz") {
qsystem($BSConfig::sign, @signargs, '-D', "$extrep/$arch/$rname.files.tar.gz") && die(" sign failed: $?\n");
link("$extrep/$arch/$rname.files.tar.gz.sig", "$extrep/$arch/$rname.files.sig");
}
}
}
}
sub deleterepo_arch {
my ($extrep) = @_;
for my $arch (ls($extrep)) {
next unless -d "$extrep/$arch";
for (grep {/\.(?:\?db|db\.tar\.gz|files|files\.tar\.gz)(?:\.sig)?$/} ls("$extrep/$arch")) {
unlink("$extrep/$arch/$_");
}
}
}
##########################################################################
sub createrepo_staticlinks {
my ($extrep, $projid, $repoid, $data, $options) = @_;
my $versioned = grep {$_ eq 'versioned'} @{$options || []};
for my $arch ('.', ls($extrep)) {
next unless -d "$extrep/$arch";
for (ls("$extrep/$arch")) {
my $link;
if (/^(.*)-Build\d\d\d\d(-Media\d?(\.license)?)$/s) {
$link = "$1$2"; # no support for versioned links
} else {
next unless -f "$extrep/$arch/$_";
}
if (/^(.*)-([^-]*)-[^-]*\.rpm$/s) {
$link = "$1.rpm";
$link = "$1-$2.rpm" if $versioned;
} elsif (/^(.*)_([^_]*)-[^_]*\.deb$/s) {
$link = "$1.deb";
$link = "${1}_$2.deb" if $versioned;
} elsif (/^(.*)-Build\d\d\d\d(-Media\d)(\.iso?(\.sha256)?)$/s) {
# product builds
$link = "$1$2$3"; # no support for versioned links
} elsif (/^(.*)-(\d+\.\d+\.\d+)-Build\d+\.\d+([-\.].*\.(gz|bz2|tbz|tgz|xz)?(?:\.sha256)?)$/s) {
# kiwi appliance
$link = "$1$3";
$link = "$1-$2$3" if $versioned;
} elsif (/^(.*)-(\d+\.\d+\.\d+)?(\.\w+)?-Build\d+\.\d+(\.(raw.install.raw.xz|raw.xz|box|json|install.iso|tbz|tgz|vmx|vmdk|vdi|vhdfixed.xz|iso|qcow2|qcow2.xz|ova)?(?:\.sha256)?)$/s) {
# kiwi appliance
my $profile = $3 || "";
$link = "$1$profile$4";
$link = "$1$profile-$2$4" if $versioned;
}
next unless $link;
unlink("$extrep/$arch/.$link"); # drop left over
symlink($_, "$extrep/$arch/.$link");
rename("$extrep/$arch/.$link", "$extrep/$arch/$link"); # atomar update
}
}
}
sub deleterepo_staticlinks {
my ($extrep) = @_;
for my $arch ('.', ls($extrep)) {
next unless -d "$extrep/$arch";
for (ls("$extrep/$arch")) {
next unless -l "$extrep/$arch/$_";
next if /\.(?:db|files)(?:\.sig)?$/;
unlink("$extrep/$arch/$_");
}
}
}
##########################################################################
sub createpatterns_rpmmd {
my ($extrep, $projid, $repoid, $data, $options) = @_;
deletepatterns_rpmmd($extrep);
my $patterns = $data->{'patterns'};
return unless @{$patterns || []};
# create patterns data structure
my @pats;
for my $pattern (@$patterns) {
push @pats, BSUtil::fromxml($pattern->{'data'}, $BSXML::pattern);
}
print " adding patterns to repodata\n";
my $pats = {'pattern' => \@pats, 'count' => scalar(@pats)};
writexml("$extrep/repodata/patterns.xml", undef, $pats, $BSXML::patterns);
my @legacyargs;
my %options = map {$_ => 1} @{$options || []};
if ($options{'legacy'}) {
push @legacyargs, '--simple-md-filenames', '--checksum=sha';
} else {
# the default in newer createrepos
push @legacyargs, '--unique-md-filenames', '--checksum=sha256';
}
qsystem('modifyrepo', "$extrep/repodata/patterns.xml", "$extrep/repodata", @legacyargs) && print(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/patterns.xml");
# for my $pattern (@{$patterns || []}) {
# my $pname = "patterns.$pattern->{'name'}";
# $pname =~ s/\.xml$//;
# print " adding pattern $pattern->{'name'} to repodata\n";
# writestr("$extrep/repodata/$pname.xml", undef, $pattern->{'data'});
# qsystem('modifyrepo', "$extrep/repodata/$pname.xml", "$extrep/repodata", @legacyargs) && print(" modifyrepo failed: $?\n");
# unlink("$extrep/repodata/$pname.xml");
# }
# re-sign changed repomd.xml file
if ($BSConfig::sign && -e "$extrep/repodata/repomd.xml") {
my @signargs;
push @signargs, '--project', $projid if $BSConfig::sign_project;
push @signargs, @{$data->{'signargs'} || []};
qsystem($BSConfig::sign, @signargs, '-d', "$extrep/repodata/repomd.xml") && die(" sign failed: $?\n");
}
}
sub deletepatterns_rpmmd {
my ($extrep) = @_;
for my $pat (ls("$extrep/repodata")) {
next unless $pat =~ /^patterns/;
unlink("$extrep/repodata/$pat");
}
}
sub createpatterns_comps {
my ($extrep, $projid, $repoid, $data, $options) = @_;
deletepatterns_comps($extrep);
my $patterns = $data->{'patterns'};
return unless @{$patterns || []};
# create comps data structure
my @grps;
for my $pattern (@$patterns) {
my $pat = BSUtil::fromxml($pattern->{'data'}, $BSXML::pattern);
my $grp = { 'id' => $pattern->{'name'} };
for (@{$pat->{'summary'}}) {
my $el = { '_content' => $_->{'_content'} };
$el->{'xml:lang'} = $_->{lang} if $_->{'lang'};
push @{$grp->{'name'}}, $el;
}
for (@{$pat->{'description'}}) {
my $el = { '_content' => $_->{'_content'} };
$el->{'xml:lang'} = $_->{'lang'} if $_->{'lang'};
push @{$grp->{'description'}}, $el;
}
for (@{$pat->{'rpm:requires'}->{'rpm:entry'}}) {
push @{$grp->{'packagelist'}->{'packagereq'} }, { '_content' => $_->{'name'}, 'type' => 'mandatory' };
}
for (@{$pat->{'rpm:recommends'}->{'rpm:entry'}}) {
push @{$grp->{'packagelist'}->{'packagereq'}}, { '_content' => $_->{'name'}, 'type' => 'default' };
}
for (@{$pat->{'rpm:suggests'}->{'rpm:entry'}}) {
push @{$grp->{'packagelist'}->{'packagereq'}}, { '_content' => $_->{'name'}, 'type' => 'optional' };
}
push @grps, $grp;
}
print " adding comps to repodata\n";
my $comps = {'group' => \@grps};
writexml("$extrep/repodata/group.xml", undef, $comps, $BSXML::comps);
my @legacyargs;
my %options = map {$_ => 1} @{$options || []};
if ($options{'legacy'}) {
push @legacyargs, '--simple-md-filenames', '--checksum=sha';
} else {
# the default in newer createrepos
push @legacyargs, '--unique-md-filenames', '--checksum=sha256';
}
qsystem('modifyrepo', "$extrep/repodata/group.xml", "$extrep/repodata", @legacyargs) && print(" modifyrepo failed: $?\n");
unlink("$extrep/repodata/group.xml");
# re-sign changed repomd.xml file
if ($BSConfig::sign && -e "$extrep/repodata/repomd.xml") {
my @signargs;
push @signargs, '--project', $projid if $BSConfig::sign_project;
push @signargs, @{$data->{'signargs'} || []};
qsystem($BSConfig::sign, @signargs, '-d', "$extrep/repodata/repomd.xml") && die(" sign failed: $?\n");
}
}
sub deletepatterns_comps {
my ($extrep) = @_;
for my $pat (ls("$extrep/repodata")) {
next unless $pat =~ /group.xml/;
unlink("$extrep/repodata/$pat");
}
}
sub createpatterns_ymp {
my ($extrep, $projid, $repoid, $data, $options) = @_;
deletepatterns_ymp($extrep, $projid, $repoid);
my $patterns = $data->{'patterns'};
return unless @{$patterns || []};
my $prp_ext = "$projid/$repoid";
$prp_ext =~ s/:/:\//g;
my $patterndb = db_open('pattern');
# get title/description data for all involved projects
my $repoinfo = $data->{'repoinfo'};
my %nprojpack;
my @nprojids = map {$_->{'project'}} @{$repoinfo->{'prpsearchpath'} || []};
if (@nprojids) {
my @args = map {"project=$_"} @nprojids;
my $nprojpack = BSRPC::rpc("$BSConfig::srcserver/getprojpack", $BSXML::projpack, 'nopackages', @args);
%nprojpack = map {$_->{'name'} => $_} @{$nprojpack->{'project'} || []};
}
for my $pattern (@$patterns) {
my $ympname = $pattern->{'name'};
$ympname =~ s/\.xml$//;
$ympname .= ".ymp";
my $pat = BSUtil::fromxml($pattern->{'data'}, $BSXML::pattern);
next if !exists $pat->{'uservisible'};
print " writing ymp for pattern $pat->{'name'}\n";
my $ymp = {};
$ymp->{'xmlns:os'} = 'http://opensuse.org/Standards/One_Click_Install';
$ymp->{'xmlns'} = 'http://opensuse.org/Standards/One_Click_Install';
my $group = {};
$group->{'name'} = $pat->{'name'};
if ($pat->{'summary'}) {
$group->{'summary'} = $pat->{'summary'}->[0]->{'_content'};
}
if ($pat->{'description'}) {
$group->{'description'} = $pat->{'description'}->[0]->{'_content'};
}
my @repos;
my @sprp = @{$repoinfo->{'prpsearchpath'} || []};
while (@sprp) {
my $sprp = shift @sprp;
my $sprojid = $sprp->{'project'};
my $srepoid = $sprp->{'repository'};
my $r = {};
$r->{'recommended'} = @sprp || !@repos ? 'true' : 'false';
$r->{'name'} = $sprojid;
if ($nprojpack{$sprojid}) {
$r->{'summary'} = $nprojpack{$sprojid}->{'title'};
$r->{'description'} = $nprojpack{$sprojid}->{'description'};
}
my $sprp_ext = "$sprojid/$srepoid";
$sprp_ext =~ s/:/:\//g;
my $url = get_downloadurl("$sprojid/$srepoid", $sprp_ext);
next unless defined $url;
$r->{'url'} = $url;
push @repos, $r;
}
$group->{'repositories'} = {'repository' => \@repos };
my @software;
for my $entry (@{$pat->{'rpm:requires'}->{'rpm:entry'} || []}) {
next if $entry->{'kind'} && $entry->{'kind'} ne 'package';
push @software, {'name' => $entry->{'name'}, 'summary' => "The $entry->{'name'} package", 'description' => "The $entry->{'name'} package."};
fillpkgdescription($software[-1], "$extrepodir/$prp_ext", $repoinfo, $entry->{'name'});
}
for my $entry (@{$pat->{'rpm:recommends'}->{'rpm:entry'} || []}) {
next if $entry->{'kind'} && $entry->{'kind'} ne 'package';
push @software, {'name' => $entry->{'name'}, 'summary' => "The $entry->{'name'} package", 'description' => "The $entry->{'name'} package."};
fillpkgdescription($software[-1], "$extrepodir/$prp_ext", $repoinfo, $entry->{'name'});
}
for my $entry (@{$pat->{'rpm:suggests'}->{'rpm:entry'} || []}) {
next if $entry->{'kind'} && $entry->{'kind'} ne 'package';
push @software, {'recommended' => 'false', 'name' => $entry->{'name'}, 'summary' => "The $entry->{'name'} package", 'description' => "The $entry->{'name'} package."};
fillpkgdescription($software[-1], "$extrepodir/$prp_ext", $repoinfo, $entry->{'name'});
}
$group->{'software'} = { 'item' => \@software };
$ymp->{'group'} = [ $group ];
writexml("$extrep/.$ympname", "$extrep/$ympname", $ymp, $BSXML::ymp);
# write database entry
my $ympidx = {'type' => 'ymp'};
$ympidx->{'name'} = $pat->{'name'} if defined $pat->{'name'};
$ympidx->{'summary'} = $pat->{'summary'}->[0]->{'_content'} if $pat->{'summary'};;
$ympidx->{'description'} = $pat->{'description'}->[0]->{'_content'} if $pat->{'description'};
$ympidx->{'path'} = $repoinfo->{'prpsearchpath'} if $repoinfo->{'prpsearchpath'};
db_store($patterndb, "$prp_ext/$ympname", $ympidx) if $patterndb;
}
}
sub deletepatterns_ymp {
my ($extrep, $projid, $repoid) = @_;
my $prp_ext = "$projid/$repoid";
$prp_ext =~ s/:/:\//g;
my $patterndb = db_open('pattern');
for my $ympname (ls($extrep)) {
next unless $ympname =~ /\.ymp$/;
db_store($patterndb, "$prp_ext/$ympname", undef) if $patterndb;
unlink("$extrep/$ympname");
}
}
##########################################################################
sub sync_to_stage {
my ($prp, $extdir, $dbgsplit, $isdelete) = @_;
my @stageservers;
if ($BSConfig::stageserver) {
if (ref($BSConfig::stageserver)) {
my @s = @{$BSConfig::stageserver};
while (@s) {
my ($k, $v) = splice(@s, 0, 2);
if ($prp =~ /^$k/) {
$v = [ $v ] unless ref $v;
@stageservers = @$v;
last;
}
}
} else {
push @stageservers, $BSConfig::stageserver;
}
}
# sync the parent directory for deletes
my $extdirx = $extdir;
$extdirx =~ s/\/[^\/]*$// if $isdelete;
for my $stageserver (@stageservers) {
if ($stageserver =~ /^rsync:\/\/([^\/]+)\/(.*)$/) {
print " running rsync to $1 at ".localtime(time)."\n";
# rsync with a timeout of 1 hour
# sync first just the binaries without deletion of the old ones, afterwards the rest(esp. meta data) and cleanup
qsystem('echo', "$extdirx\0", 'rsync', '-ar0', @binsufsrsync, '--include=*/', '--exclude=*', '--timeout', '7200', '--files-from=-', $extrepodir, "$1::$2") && die(" rsync failed at ".localtime(time).": $?\n");
qsystem('echo', "$extdirx\0", 'rsync', '-ar0', '--delete-after', '--exclude=repocache', '--delete-excluded', '--timeout', '7200', '--files-from=-', $extrepodir, "$1::$2") && die(" rsync failed at ".localtime(time).": $?\n");
}
if ($stageserver =~ /^script:(\/.*)$/) {
print " running sync script $1 at ".localtime(time)."\n";
if ($isdelete) {
qsystem($1, $prp) && die(" sync script failed at ".localtime(time).": $?\n");
} else {
qsystem($1, $prp, $extdirx) && die(" sync script failed at ".localtime(time).": $?\n");
}
}
}
# push done trigger sync to other mirrors
mkdir_p($extrepodir_sync);
my $filename = $prp;
$filename =~ s/\//_/g;
$filename .= $dbgsplit if $dbgsplit;
writestr("$extrepodir_sync/.$$:$filename", "$extrepodir_sync/$filename", "$extdir\0");
if ($BSConfig::stageserver_sync && $BSConfig::stageserver_sync =~ /^rsync:\/\/([^\/]+)\/(.*)$/) {
print " running trigger rsync to $1 at ".localtime(time)."\n";
# small sync, timout 1 minute
qsystem('rsync', '-a', '--timeout', '120', "$extrepodir_sync/$filename", "$1::$2/$filename") && warn(" trigger rsync failed at ".localtime(time).": $?\n");
}
}
sub map_to_extrep {
my ($prp, $prp_ext) = @_;
my $extrep = "$extrepodir/$prp_ext";
return $extrep unless $BSConfig::publishredirect;
if ($BSConfig::publishedredirect_use_regex || $BSConfig::publishedredirect_use_regex) {
for my $key (sort {$b cmp $a} keys %{$BSConfig::publishredirect}) {
if ($prp =~ /^$key/) {
$extrep = $BSConfig::publishredirect->{$key};
last;
}
}
} elsif (exists($BSConfig::publishredirect->{$prp})) {
$extrep = $BSConfig::publishredirect->{$prp};
}
$extrep = $extrep->($prp, $prp_ext) if $extrep && ref($extrep) eq 'CODE';
return $extrep;
}
sub get_downloadurl {
my ($prp, $prp_ext) = @_;
if ($BSConfig::prp_ext_map && exists $BSConfig::prp_ext_map->{$prp}) {
return $BSConfig::prp_ext_map->{$prp};
}
my $extrep = map_to_extrep($prp, $prp_ext);
$extrep = [ $extrep ] unless ref $extrep;
return $extrep->[2] if $extrep->[2];
return undef unless $BSConfig::repodownload;
if ($extrep->[0] =~ /^\Q$BSConfig::bsdir\E\/repos\/(.*)$/) {
my $url = "$BSConfig::repodownload/$1/";
$url =~ s!//$!/!;
return $url;
}
return "$BSConfig::repodownload/$prp_ext/";
}
sub deleterepo {
my ($projid, $repoid, $dbgsplit) = @_;
my $prp = "$projid/$repoid";
print " deleting repository\n";
my $prp_ext = $prp;
$prp_ext =~ s/:/:\//g;
my $extrep = map_to_extrep($prp, $prp_ext);
return unless $extrep;
$extrep = $extrep->[0] if ref $extrep;
$extrep .= $dbgsplit if $dbgsplit;
$prp_ext .= $dbgsplit if $dbgsplit;
if (! -d $extrep) {
if ($extrep =~ /\Q$extrepodir\E\/(.+)$/) {
my $extdir = $1;
$extdir =~ s/\/.*?$//;
rmdir("$extrepodir/$extdir");
}
return if $dbgsplit;
print " nothing to delete...\n";
unlink("$reporoot/$prp/:repoinfo");
rmdir("$reporoot/$prp");
return;
}
# get old repoinfo
my $repoinfo = {};
if (-s "$reporoot/$prp/:repoinfo") {
$repoinfo = BSUtil::retrieve("$reporoot/$prp/:repoinfo", 1) || {};
delete $repoinfo->{'splitdebug'} if $dbgsplit; # do not recurse!
}
# delete all binaries
my $subdir = $repoinfo->{'subdir'} || '';
my @archs = sort(ls($extrep));
if ($subdir) {
@archs = map {$_ eq $subdir ? sort(map {"$subdir/$_"} ls("$extrep/$subdir")) : $_} @archs;
}
my @db_deleted;
for my $arch (@archs) {
next if $arch =~ /^\./;
next if $arch eq 'repodata' || $arch eq 'repocache' || $arch eq 'media.1' || $arch eq 'descr';
my $r = "$extrep/$arch";
next unless -d $r;
for my $bin (ls($r)) {
next if $bin eq 'media_info';
my $p = "$arch/$bin";
print " - $p\n";
if (-d "$r/$bin") {
BSUtil::cleandir("$r/$bin");
rmdir("$r/$bin") || die("rmdir $r/$bin: $!\n");
} else {
unlink("$r/$bin") || die("unlink $r/$bin: $!\n");
}
push @db_deleted, $p if $p =~ /\.(?:$binsufsre)$/;
}
}
# update published database
my $binarydb = db_open('binary');
updatebinaryindex($binarydb, [ map {"$prp_ext/$_"} @db_deleted ], []) if $binarydb;
my $repoinfodb = db_open('repoinfo');
db_store($repoinfodb, $dbgsplit ? "$prp$dbgsplit" : $prp, undef) if $repoinfodb;
if ($BSConfig::markfileorigins) {
for my $f (sort @db_deleted) {
my $req = {
'uri' => "$BSConfig::markfileorigins/$prp_ext/$f",
'request' => 'HEAD',
'maxredirects' => 3,
'timeout' => 10,
'ignorestatus' => 1,
};
eval {
BSRPC::rpc($req, undef, 'cmd=deleted');
};
print " $f: $@" if $@;
}
}
# delete ymps so they get removed from the database
deletepatterns_ymp($extrep, $projid, $repoid);
# delete everything else
qsystem('rm', '-rf', $extrep);
if ($extrep =~ /\Q$extrepodir\E\/(.+)$/) {
my $extdir = $1;
sync_to_stage($prp, $extdir, $dbgsplit, 1);
rmdir("$extrepodir/$extdir");
}
# also delete the split debug repo
deleterepo($projid, $repoid, $repoinfo->{'splitdebug'}) if $repoinfo->{'splitdebug'} && !$dbgsplit;
if (!$dbgsplit && $BSConfig::packtrack && (($repoinfo->{'projectkind'} || '') eq 'maintenance_release' || grep {$prp =~ /^$_/} @$BSConfig::packtrack)) {
my $packtrack = {};
print " sending binary release tracking notification\n";
BSNotify::notify('PACKTRACK', { project => $projid , 'repo' => $repoid }, Storable::nfreeze([ map { $packtrack->{$_} } sort keys %$packtrack ]));
}
# delete repoinfo
unlink("$reporoot/$prp/:repoinfo") unless $dbgsplit;
rmdir("$reporoot/$prp");
}
sub publish {
my ($projid, $repoid, $dbgsplit, $dbgpacktrack) = @_;
my $prp = "$projid/$repoid";
print localtime(time)." publishing $prp\n";
# get info from source server about this project/repository
# we specify "withsrcmd5" so that we get the patternmd5. It still
# works with "nopackages".
my $projpack = BSRPC::rpc("$BSConfig::srcserver/getprojpack", $BSXML::projpack, 'withrepos', 'expandedrepos', 'withsrcmd5', 'nopackages', "project=$projid", "repository=$repoid");
if (!$projpack->{'project'}) {
# project is gone
deleterepo($projid, $repoid);
return;
}
my $proj = $projpack->{'project'}->[0];
die("no such project $projid\n") unless $proj && $proj->{'name'} eq $projid;
if (!$proj->{'repository'}) {
# repository is gone
deleterepo($projid, $repoid);
return;
}
my $repo = $proj->{'repository'}->[0];
die("no such repository $repoid\n") unless $repo && $repo->{'name'} eq $repoid;
# this is the already expanded path as we used 'expandedrepos' above
my $prpsearchpath = $repo->{'path'};
# we need the config for repotype/patterntype
my $config = BSRPC::rpc("$BSConfig::srcserver/getconfig", undef, "project=$projid", "repository=$repoid");
$config = Build::read_config('noarch', [ split("\n", $config) ]);
if (!@{$config->{'repotype'} || []}) {
# guess repotype from binarytype
my $binarytype = $config->{'binarytype'} || '';
my $repotype;
$repotype = 'rpm-md' if $binarytype eq 'rpm';
$repotype = 'debian' if $binarytype eq 'deb';
$repotype = 'arch' if $binarytype eq 'arch';
$repotype ||= 'rpm-md';
$config->{'repotype'} = [ $repotype ];
}
my %repotype;
for (@{$config->{'repotype'} || []}) {
if (/^(.*?):(.*)$/) {
$repotype{$1} = [ split(':', $2) ];
} else {
$repotype{$_} = [];
}
}
$dbgsplit ||= '' if $repotype{'splitdebug'} && $repotype{'splitdebug'}->[0];
my $archorder;
$archorder = $repotype{'archorder'} if $repotype{'archorder'};
# is there a special subdirectory for binary packages configured?
my $subdir = '';
if ($repotype{'packagesubdir'} && $repotype{'packagesubdir'}->[0]) {
$subdir = $repotype{'packagesubdir'}->[0];
BSVerify::verify_filename($subdir);
}
my $prp_ext = $prp;
$prp_ext =~ s/:/:\//g;
my $extrep = map_to_extrep($prp, $prp_ext);
return unless $extrep;
$extrep = $extrep->[0] if ref $extrep;
$extrep .= $dbgsplit if $dbgsplit;
$prp_ext .= $dbgsplit if $dbgsplit;
# get us the lock
local *F;
open(F, '>', "$reporoot/$prp/.finishedlock") || die("$reporoot/$prp/.finishedlock: $!\n");
if (!flock(F, LOCK_EX | LOCK_NB)) {
print " waiting for lock...\n";
flock(F, LOCK_EX) || die("flock: $!\n");
print " got the lock...\n";
}
# we now know that $reporoot/$prp/*/:repo will not change.
# Build repo by mixing all architectures.
my @archs = @{$repo->{'arch'} || []};
my %bins;
my %bins_id;
my $binaryorigins = {};
my @updateinfos;
my $updateinfos_state;
my $appdatas;
my $appdatas_state;
my %appdatas_seen;
my %deltas; # XXX remove hack
my %deltainfos;
my $deltainfos_state;
my %kiwireport; # store collected report (under the original name)
my %kiwimedium; # maps published name to original name
my $kiwiindex = ''; # store collected index parts
if ($archorder) {
my %archorder = map {$_ => 1} @$archorder;
my %archs = map {$_ => 1} @archs;
# last one wins in code below
@archs = ((grep {!$archorder{$_}} @archs), (grep {$archs{$_}} reverse(@$archorder)));
}
# drop entire repo it source :repo's have disappeared altogether. We need to find a way
# to specify this explicit instead checking all :repo's.
my $found_repo;
for my $arch (@archs) {
my $r = "$reporoot/$prp/$arch/:repo";
$found_repo = 1 if -e $r;
}
if (!defined($found_repo)) {
deleterepo($projid, $repoid);
return;
}
for my $arch (@archs) {
my $r = "$reporoot/$prp/$arch/:repo";
my $repoinfo = {};
if (-s "${r}info") {
$repoinfo = BSUtil::retrieve("${r}info") || {};
}
$repoinfo->{'binaryorigins'} ||= {};
for my $rbin (sort(ls($r))) {
my $bin = $rbin;
if ($bin =~ /:updateinfo.xml$/) {
# collect updateinfo data
my $updateinfoxml = readstr("$r/$bin", 1) || '';
$updateinfos_state .= Digest::MD5::md5_hex($updateinfoxml);
my $updateinfo = readxml("$r/$bin", $BSXML::updateinfo, 1) || {};
push @updateinfos, @{$updateinfo->{'update'} || []};
}
if ($bin =~ /-appdata.xml$/) {
# collect application data
my $appdataxml = readstr("$r/$bin", 1) || '';
my $appdatamd5 = Digest::MD5::md5_hex($appdataxml);
next if $appdatas_seen{$appdatamd5};
$appdatas_seen{$appdatamd5} = 1;
$appdatas_state .= $appdatamd5;
my $appdata;
eval {
$appdata = XML::Simple::XMLin($appdataxml, 'ForceArray' => 1);
};
$appdata ||= {};
# merge the applications/components
if ($appdatas) {
if ($appdata->{'version'}) {
my $v1 = $appdata->{'version'};
my $v2 = $appdatas->{'version'} || '';
$v1 =~ s/(\d+)/substr("00000000$1", -9)/ge;
$v2 =~ s/(\d+)/substr("00000000$1", -9)/ge;
$appdatas->{'version'} = $appdata->{'version'} if $v1 gt $v2;
}
if ($appdata->{'component'} || $appdatas->{'component'}) {
$appdatas->{'component'} = delete $appdatas->{'application'} if $appdatas->{'application'};
push @{$appdatas->{'component'}}, @{$appdata->{'component'} || $appdata->{'application'} || []};
} else {
push @{$appdatas->{'application'}}, @{$appdata->{'application'} || []};
}
} else {
$appdatas = $appdata;
}
}
if ($bin =~ /^(.*\.rpm)::(.*\.drpm)$/) {
# special drpm handling: only take it if we took the corresponding rpm
if ($bin =~ /^(.+-[^-]+-[^-]+\.([a-zA-Z][^\/\.\-]*)\.rpm)::(.*\.drpm)$/) {
if ($bins{$subdir ? "$subdir/$2/$1" : "$2/$1"} eq "$r/$1") {
# ok, took it. also take delta
$bin = $3;
push @{$deltas{"$r/$1"}}, "$r/$rbin";
}
}
}
$bin =~ s/^.*?:://; # strip package name for now
#next unless $bin =~ /\.(?:$binsufsre)$/;
my $p;
if ($bin =~ /^.+-[^-]+-[^-]+\.([a-zA-Z][^\/\.\-]*)\.d?rpm$/) {
$p = "$1/$bin";
$p = $1 eq 'src' || $1 eq 'nosrc' ? "SRPMS/$bin" : "RPMS/$bin" if $repotype{'resarchhack'};
} elsif ($bin =~ /^.+_[^_]+_([^_\.]+)\.deb$/) {
$p = "$1/$bin";
} elsif ($bin =~ /\.exe$/) {
$p = "$bin";
} elsif ($bin =~ /\.d?rpm$/) {
# legacy format
my $q = Build::query("$r/$rbin", 'evra' => 1);
next unless $q;
$p = "$q->{'arch'}/$q->{'name'}-$q->{'version'}-$q->{'release'}.$q->{'arch'}.rpm";
} elsif ($bin =~ /\.deb$/) {
# legacy format
my $q = Build::query("$r/$rbin", 'evra' => 1);
$p = "$q->{'arch'}/$q->{'name'}_$q->{'version'}";
$p .= "-$q->{'release'}" if defined $q->{'release'};
$p .= "_$q->{'arch'}.deb";
} elsif ($bin =~ /\.(?:pkg\.tar\.gz|pkg\.tar\.xz)$/) {
$p = "$arch/$bin";
$p = "i686/$bin" if $arch eq 'i586'; # HACK
} elsif ($bin =~ /\.(?:$binsufsre)$/) {
# our default
my $q = Build::query("$r/$rbin", 'evra' => 1);
next unless $q && defined($q->{'arch'});
$p = "$q->{'arch'}/$bin";
} else {
if ($bin =~ /\.iso(?:\.sha256)?$/) {
$p = "iso/$bin";
$kiwimedium{$p} = $1 if $bin =~ /(.+)\.iso$/;
} elsif ($bin =~ /\.raw(?:\.install)?(?:\.(?:gz|bz2|xz))?(?:\.sha256)?$/) {
$p = "$bin";
} elsif ($bin =~ /-Build\d.*\.(?:tbz|tgz|tar|tar\.gz|tar\.bz2|tar\.xz)(?:\.sha256)?$/) {
$p = "$bin";
} elsif ($bin =~ /\.tar(?:\.(?:gz|bz2|xz))?(?:\.sha256)?$/) {
$p = "$bin";
} elsif ($bin =~ /\.squashfs$/) {
$p = "$bin"; # for simpleimage builds
} elsif ($bin =~ /\.diff\.(?:gz)(?:\.sha256)?$/) {
$p = "$bin";
} elsif ($bin =~ /\.dsc(?:\.sha256)?$/) {
$p = "$bin";
} elsif ($bin =~ /\.(?:box|json|ovf|qcow2|qcow2\.xz|vdi|vhdfixed.xz|vmx|vmdk)(?:\.sha256)?$/) {
$p = "$bin";
} elsif ($bin =~ /^(.*)\.packages$/) {
$p = "$bin";
} elsif ($bin =~ /^(.*)\.report$/) {
# collect kiwi reports
$kiwireport{$1} = readxml("$r/$rbin", $BSXML::report, 1);
next;
} elsif ($bin =~ /^(.*)\.index$/) {
# collect virt-builder index parts
$kiwiindex .= readstr("$r/$bin", 1) . "\n";
next;
} elsif (-d "$r/$rbin") {
$p = "repo/$bin";
if ($repotype{'slepool'}) {
# HACK: do fancy sle repo renaming
my $name = $repotype{'slepool'}->[0] || 'product';
$p = $bin;
if ($bin =~ /.*-Media1(\.license|)$/) {
$p = "$name$1";
} elsif ($bin =~ /-Media3$/) {
$p = "${name}_debug";
} elsif ($bin =~ /-Media2$/) {
my $rbin3 = $rbin;
$rbin3 =~ s/2$/3/;
if (-d "$r/$rbin3") {
$p = "${name}_source"; # 3 media available, 2 is source
} else {
$p = "${name}_debug"; # source is on media 1, 2 is debug
}
}
$p = $bin if $kiwimedium{$p}; # what???
}
$kiwimedium{$p} = $bin;
} else {
next;
}
}
next unless defined $p;
$p = "$subdir/$p" if $subdir;
# next if $bins{$p}; # first arch wins
my @s = stat("$reporoot/$prp/$arch/:repo/$rbin");
next unless @s;
if ($bins{$p}) {
if (!$archorder) {
# keep old file (FIXME: should do this different)
my @s2 = stat("$extrep/$p");
next if !@s2 || "$s[9]/$s[7]/$s[1]" ne "$s2[9]/$s2[7]/$s2[1]";
}
# replace already taken binary. kill taken deltas again
for my $d (@{$deltas{"$r/$rbin"} || []}) {
for my $dp (grep {$bins{$_} eq $d} keys %bins) {
delete $bins{$dp};
delete $bins_id{$dp};
delete $binaryorigins->{$dp};
delete $deltainfos{$dp};
}
}
}
$bins{$p} = "$r/$rbin";
$bins_id{$p} = "$s[9]/$s[7]/$s[1]";
$binaryorigins->{$p} = $repoinfo->{'binaryorigins'}->{$rbin} if defined $repoinfo->{'binaryorigins'}->{$rbin};
if ($rbin =~ /^(.*)\.drpm$/) {
# we took a delta rpm. collect desq if possible
my $dseq = "$r/$1.dseq";
if (-s $dseq) {
my %dseq;
for (split("\n", readstr($dseq, 1) || '')) {
$dseq{$1} = $2 if /^(.*?): (.*)$/s;
}
my @needed = qw{Name Epoch Version Release Arch OldName OldEpoch OldVersion OldRelease OldArch Seq};
if (!grep {!exists($dseq{$_})} @needed) {
# got all required fields. convert to correct data
my $dinfo = {'name' => $dseq{'Name'}, 'epoch' => $dseq{'Epoch'} || 0, 'version' => $dseq{'Version'}, 'release' => $dseq{'Release'}, 'arch' => $dseq{'Arch'}};
$dinfo->{'delta'} = [ {'oldepoch' => $dseq{'OldEpoch'} || 0, 'oldversion' => $dseq{'OldVersion'}, 'oldrelease' => $dseq{'OldRelease'}, 'filename' => $p, 'sequence' => $dseq{'Seq'}} ];
$deltainfos{$p} = $dinfo;
}
}
}
}
}
# calculate deltainfos_state
if (%deltainfos) {
$deltainfos_state = '';
for my $p (sort keys %deltainfos) {
my @s = stat($bins{$p});
my $id = "$s[9]/$s[7]/$s[1]";
if ($bins{$p} =~ /^(.*)\.drpm$/) {
@s = stat("$1.dseq");
$id .= "/$s[9]/$s[7]/$s[1]";
}
$deltainfos_state .= Digest::MD5::md5_hex($id);
}
}
# do debug filtering if requested
if (defined($dbgsplit)) {
if ($dbgsplit) {
for my $p (keys %bins) {
next if $p =~ /-debug(?:info|source)-.*rpm$/;
delete $bins{$p};
delete $deltainfos{$p};
}
} else {
for my $p (keys %bins) {
next unless $p =~ /-debug(?:info|source)-.*rpm$/;
delete $bins{$p};
delete $deltainfos{$p};
}
}
}
# now update external repository
my $changed = 0;
my @db_deleted; # for published db update
my @db_changed; # for published db update
my @changed; # all changed files for hooks.
my %bins_done;
@archs = sort(ls($extrep));
if ($subdir) {
@archs = map {$_ eq $subdir ? sort(map {"$subdir/$_"} ls("$extrep/$subdir")) : $_} @archs;
}
for my $arch (@archs) {
next if $arch =~ /^\./;
next if $arch eq 'repodata' || $arch eq 'repocache' || $arch eq 'media.1' || $arch eq 'descr';
next if $arch =~ /\.repo$/;
next if $arch eq 'Packages' || $arch eq 'Packages.gz' || $arch eq 'Sources' || $arch eq 'Sources.gz' || $arch eq 'Release' || $arch eq 'Release.gz' || $arch eq 'Release.key';
my $r = "$extrep/$arch";
if (-f $r) {
$r = $extrep;
my $bin = $arch;
my $p = $arch;
my @s = lstat("$r/$bin");
if (!exists($bins{$p})) {
print " - $p\n";
unlink("$r/$bin") || die("unlink $r/$bin: $!\n");
push @db_deleted, $p if $p =~ /\.(?:$binsufsre)$/;
$changed = 1;
next;
}
if ("$s[9]/$s[7]/$s[1]" ne $bins_id{$p}) {
unlink("$r/$bin") || die("unlink $r/$bin: $!\n");
link($bins{$p}, "$r/$bin") || die("link $bins{$p} $r/$bin: $!\n");
push @db_changed, $p if $p =~ /\.(?:$binsufsre)$/;
push @changed, $p;
$changed = 1;
}
$bins_done{$p} = 1;
next;
}
if ($bins{$arch}) {
my @s = lstat($r);
die("$r: $!\n") unless @s;
next if "$s[9]/$s[7]/$s[1]" eq $bins_id{$arch};
if (-d _) {
if (! -l $bins{$arch} && -d _) {
my $info1 = BSUtil::treeinfo($bins{$arch});
my $info2 = BSUtil::treeinfo($r);
if (join(',', @$info1) eq join(',', @$info2)) {
$bins_done{$arch} = 1;
next;
}
print " ! $arch\n";
BSUtil::cleandir($r);
rmdir($r) || die("rmdir $r: $!\n");
}
if (! -l $bins{$arch} && -d _) {
BSUtil::linktree($bins{$arch}, $r);
} else {
link($bins{$arch}, $r) || die("link $bins{$arch} $r: $!\n");
}
push @db_changed, $arch if $arch =~ /\.(?:$binsufsre)$/;
push @changed, $arch;
$changed = 1;
next;
}
}
next unless -d $r;
for my $bin (sort(ls($r))) {
my $p = "$arch/$bin";
my @s = lstat("$r/$bin");
die("$r/$bin: $!\n") unless @s;
if (!exists($bins{$p})) {
print " - $p\n";
if (-d _) {
BSUtil::cleandir("$r/$bin");
rmdir("$r/$bin") || die("rmdir $r/$bin: $!\n");
} else {
unlink("$r/$bin") || die("unlink $r/$bin: $!\n");
}
push @db_deleted, $p if $p =~ /\.(?:$binsufsre)$/;
$changed = 1;
next;
}
if ("$s[9]/$s[7]/$s[1]" ne $bins_id{$p}) {
# changed, link over
if (-d _) {
if (! -l $bins{$p} && -d _) {
# both are directories, compare info
# should MIX instead?
my $info1 = BSUtil::treeinfo($bins{$p});
my $info2 = BSUtil::treeinfo("$r/$bin");
if (join(',', @$info1) eq join(',', @$info2)) {
$bins_done{$p} = 1;
next;
}
}
print " ! $p\n";
BSUtil::cleandir("$r/$bin");
rmdir("$r/$bin") || die("rmdir $r/$bin: $!\n");
} else {
print " ! $p\n";
unlink("$r/$bin") || die("unlink $r/$bin: $!\n");
}
if (! -l $bins{$p} && -d _) {
BSUtil::linktree($bins{$p}, "$r/$bin");
} else {
link($bins{$p}, "$r/$bin") || die("link $bins{$p} $r/$bin: $!\n");
}
push @db_changed, $p if $p =~ /\.(?:$binsufsre)$/;
push @changed, $p;
$changed = 1;
}
$bins_done{$p} = 1;
}
}
for my $p (sort keys %bins) {
next if $bins_done{$p};
# a new one
my ($arch, $bin);
if ($p =~ /^(.*)\/([^\/]*)$/s) {
($arch, $bin) = ($1, $2);
} else {
($arch, $bin) = ('.', $p);
}
my $r = "$extrep/$arch";
mkdir_p($r) unless -d $r;
print " + $p\n";
if (! -l $bins{$p} && -d _) {
BSUtil::linktree($bins{$p}, "$r/$bin");
} else {
link($bins{$p}, "$r/$bin") || die("link $bins{$p} $r/$bin: $!\n");
}
push @db_changed, $p if $p =~ /\.(?:$binsufsre)$/;
push @changed, $p;
$changed = 1;
}
# Write the kiwi index file if we got it
if ($kiwiindex) {
my $oldkiwiindex = readstr("$extrep/index", 1) || '';
if ($oldkiwiindex ne $kiwiindex) {
writestr("$extrep/index", undef, $kiwiindex);
push @changed, "$extrep/index";
$changed = 1;
}
}
close F; # release repository lock
my $title = $proj->{'title'} || $projid;
$title .= " ($repoid)";
$title =~ s/\n/ /sg;
my $state;
$state = $proj->{'patternmd5'} || '';
$state .= "\0".join(',', @{$config->{'repotype'} || []}) if %bins;
$state .= "\0".($proj->{'title'} || '') if %bins;
$state .= "\0".join(',', @{$config->{'patterntype'} || []}) if $proj->{'patternmd5'};
$state .= "\0".join('/', map {"$_->{'project'}/$_->{'repository'}"} @{$prpsearchpath || []}) if $proj->{'patternmd5'};
$state .= "\0".$updateinfos_state if $updateinfos_state;
$state .= "\0".$appdatas_state if $appdatas_state;
$state .= "\0".$deltainfos_state if $deltainfos_state;
$state = Digest::MD5::md5_hex($state) if $state ne '';
# get us the old repoinfo, so we can compare the state
my $repoinfo = {};
my $packtrackcache;
if (-s "$reporoot/$prp/:repoinfo") {
$repoinfo = BSUtil::retrieve("$reporoot/$prp/:repoinfo") || {};
$packtrackcache = $repoinfo->{'trackercache'} if $repoinfo->{'trackercache'} && ($repoinfo->{'trackercacheversion'} || '') eq '1';
}
if (($repoinfo->{'state'} || '') ne $state) {
$changed = 1;
}
if (($repoinfo->{'splitdebug'} || '') ne (($repotype{'splitdebug'} || [])->[0] || '')) {
deleterepo($projid, $repoid, $repoinfo->{'splitdebug'}) if $repoinfo->{'splitdebug'};
$changed = 1;
}
if (!$changed && !$dbgsplit) {
print " nothing changed\n";
return;
}
mkdir_p($extrep) unless -d $extrep;
# get sign key
my $signargs = [];
my $signkey = BSRPC::rpc("$BSConfig::srcserver/getsignkey", undef, "project=$projid", "withpubkey=1", "autoextend=1", "withalgo=1");
my $pubkey;
my $algo;
if ($signkey) {
($signkey, $pubkey) = split("\n", $signkey, 2);
$algo = $1 if $signkey && $signkey =~ s/^(\S+)://;
mkdir_p("$uploaddir");
writestr("$uploaddir/publisher.$$", undef, $signkey);
$signargs = [ '-P', "$uploaddir/publisher.$$" ];
push @$signargs, '-h', 'sha256' if $algo && $algo eq 'rsa';
undef $pubkey unless $pubkey && length($pubkey) > 2; # not a valid pubkey
}
if (!$pubkey) {
if ($BSConfig::sign_project && $BSConfig::sign) {
local *S;
open(S, '-|', $BSConfig::sign, '--project', $projid, '-p') || die("$BSConfig::sign: $!\n");;
$pubkey = '';
1 while sysread(S, $pubkey, 4096, length($pubkey));
if (!close(S)) {
print "sign -p failed: $?\n";
$pubkey = undef;
}
} elsif ($BSConfig::keyfile) {
if (-e $BSConfig::keyfile) {
$pubkey = readstr($BSConfig::keyfile);
} else {
print "WARNING: configured sign key $BSConfig::keyfile does not exist\n";
}
}
}
# get all patterns
my $patterns = [];
if ($proj->{'patternmd5'}) {
$patterns = getpatterns($projid);
}
# collect packtrack data (if needed)
my $packtrack;
if ($BSConfig::packtrack && (($proj->{'kind'} || '') eq 'maintenance_release' || grep {$prp =~ /^$_/} @$BSConfig::packtrack)) {
$packtrack = $dbgpacktrack || {};
my %cache = @{$packtrackcache || []};
for my $bin (sort keys %bins) {
if ($bin =~ /\.(?:$binsufsre)$/) {
my $res;
my @s = stat("$extrep/$bin");
next unless @s;
my $c = $cache{"$bin/$s[9]/$s[7]/$s[1]"};
if ($c) {
my @d = qw{arch name epoch version release disturl buildtime};
$res = {};
for (@$c) {
my $dd = shift @d;
$res->{$dd} = $_ if defined $_;
}
} else {
eval {
$res = Build::query("$extrep/$bin", 'evra' => 1, 'buildtime' => 1, 'disturl' => 1);
};
next unless $res;
}
my $pt = {
'project' => $projid,
'repository' => $repoid,
};
$pt->{'arch'} = $1 if $bins{$bin} =~ /^\Q$reporoot\E\/\Q$prp\E\/([^\/]+)\//;
$pt->{'package'} = $binaryorigins->{$bin} if $binaryorigins->{$bin};
for (qw{name epoch version release disturl buildtime}) {
$pt->{$_} = $res->{$_} if defined $res->{$_};
}
$pt->{'binaryarch'} = $res->{'arch'} if defined $res->{'arch'};
$pt->{'id'} = "$bin/$s[9]/$s[7]/$s[1]";
$packtrack->{$bin} = $pt;
} elsif ($kiwimedium{$bin} && $kiwireport{$kiwimedium{$bin}}) {
my $medium = $bin;
$medium =~ s/.*\///; # basename
for my $kb (@{$kiwireport{$kiwimedium{$bin}}->{'binary'} || []}) {
my $pt = { %$kb };
delete $pt->{'_content'};
$pt->{'medium'} = $medium;
my $fn = '';
$fn .= "/".(defined($pt->{$_}) ? $pt->{$_} : '') for qw{binaryarch name epoch version release};
$packtrack->{"$medium$fn"} = $pt;
}
}
}
# argh, find patchinforef and put it in update
if (@updateinfos) {
for my $up (@updateinfos) {
for my $cl (@{($up->{'pkglist'} || {})->{'collection'} || []}) {
for my $pkg (@{$cl->{'package'} || []}) {
my $pn = ($subdir ? "$subdir/" : '') . "$pkg->{'arch'}/$pkg->{'filename'}";
if ($packtrack->{$pn}) {
$packtrack->{$pn}->{'patchinforef'} = $up->{'patchinforef'} if $up->{'patchinforef'};
$packtrack->{$pn}->{'updateinfoid'} = $up->{'id'};
$packtrack->{$pn}->{'updateinfoversion'} = $up->{'version'};
# XXX: do this in hook?
my $supportstatus = $pkg->{'supportstatus'};
# workaround for broken code11 imports
if ($supportstatus) {
$supportstatus =~ s/^support_//;
$packtrack->{$pn}->{'supportstatus'} = $supportstatus;
}
}
}
}
}
}
}
undef $packtrackcache;
# create and store the new repoinfo
$repoinfo = {
'prpsearchpath' => $prpsearchpath,
'binaryorigins' => $binaryorigins,
'title' => $title,
'state' => $state,
};
$repoinfo->{'projectkind'} = $proj->{'kind'} if $proj->{'kind'};
$repoinfo->{'arch'} = $repo->{'arch'} if $repo->{'arch'};
$repoinfo->{'splitdebug'} = $repotype{'splitdebug'}->[0] if defined $dbgsplit;
$repoinfo->{'subdir'} = $subdir if $subdir;
$repoinfo->{'base'} = $repo->{'base'} if $repo->{'base'};
# store repoinfo on disk
if (!$dbgsplit) {
if ($state ne '') {
BSUtil::store("$reporoot/$prp/.:repoinfo", "$reporoot/$prp/:repoinfo", $repoinfo);
} else {
unlink("$reporoot/$prp/:repoinfo");
}
}
# do debug filtering if requested
if (defined($dbgsplit)) {
for (keys %$binaryorigins) {
delete $binaryorigins->{$_} unless $bins{$_};
}
if (@updateinfos) {
my $dbgsplittype = ($repotype{'splitdebug'}->[1]) || 'mainupdateinfo';
@updateinfos = () if $dbgsplit;
if ($dbgsplittype ne 'mainupdateinfo' && !$dbgsplit) {
for my $up (@updateinfos) {
for my $cl (@{($up->{'pkglist'} || {})->{'collection'} || []}) {
next unless $cl->{'package'};
my $haveremovedpkg;
for my $pkg (@{$cl->{'package'}}) {
next unless $pkg->{'filename'} =~ /-debug(?:info|source)-.*rpm$/;
$pkg = undef;
$haveremovedpkg = 1;
}
next unless $haveremovedpkg;
$cl->{'package'} = [ grep {defined($_)} @{$cl->{'package'}} ];
}
}
}
}
}
# store repoinfo in published database
my $repoinfodb = db_open('repoinfo');
db_store($repoinfodb, $dbgsplit ? "$prp$dbgsplit" : $prp, $state ne '' ? $repoinfo : undef) if $repoinfodb;
# put in published database
my $binarydb = db_open('binary');
updatebinaryindex($binarydb, [ map {"$prp_ext/$_"} @db_deleted ], [ map {"$prp_ext/$_"} @db_changed ]) if $binarydb;
# mark file origins so we can gather per package statistics
if ($BSConfig::markfileorigins) {
print " marking file origins\n";
for my $f (sort @db_changed) {
my $origin = $binaryorigins->{$f};
$origin = "?" unless defined $origin;
my $req = {
'uri' => "$BSConfig::markfileorigins/$prp_ext/$f",
'request' => 'HEAD',
'maxredirects' => 3,
'timeout' => 10,
'ignorestatus' => 1,
};
eval {
BSRPC::rpc($req, undef, 'cmd=setpackage', "package=$origin");
};
print " $f: $@" if $@;
}
for my $f (sort @db_deleted) {
my $req = {
'uri' => "$BSConfig::markfileorigins/$prp_ext/$f",
'request' => 'HEAD',
'maxredirects' => 3,
'timeout' => 10,
'ignorestatus' => 1,
};
eval {
BSRPC::rpc($req, undef, 'cmd=deleted');
};
print " $f: $@" if $@;
}
}
# create repositories and patterns
my %patterntype;
for (@{$config->{'patterntype'} || []}) {
if (/^(.*?):(.*)$/) {
$patterntype{$1} = [ split(':', $2) ];
} else {
$patterntype{$_} = [];
}
}
if ($repotype{'rpm-md-legacy'}) {
$repotype{'rpm-md'} = $repotype{'rpm-md-legacy'};
unshift @{$repotype{'rpm-md'}}, 'legacy';
delete $repotype{'rpm-md-legacy'};
}
if ($BSConfig::publishprogram && $BSConfig::publishprogram->{$prp}) {
local *PPLOCK;
open(PPLOCK, '>', "$reporoot/$prp/.pplock") || die("$reporoot/$prp/.pplock: $!\n");
flock(PPLOCK, LOCK_EX) || die("flock: $!\n");
if (xfork()) {
close PPLOCK;
return;
}
if (system($BSConfig::publishprogram->{$prp}, $prp, $extrep)) {
die(" $BSConfig::publishprogram->{$prp} failed: $?\n");
}
goto publishprog_done;
}
my $xrepoid = $repoid;
$xrepoid .= $dbgsplit if $dbgsplit;
my @repotags = @{$repotype{'repotag'} || []};
# de-escape (mostly done for ':'
s/%([a-fA-F0-9]{2})/chr(hex($1))/ge for @repotags;
if (grep {$_ eq '-obsrepository'} @repotags) {
@repotags = grep {$_ ne '-obsrepository'} @repotags;
} else {
my $obsname = $BSConfig::obsname || 'build.opensuse.org';
push @repotags, "obsrepository://$obsname/$projid/$repoid";
}
my $data = {
'subdir' => $subdir,
'signargs' => $signargs,
'pubkey' => $pubkey,
'repoinfo' => $repoinfo,
'updateinfos' => \@updateinfos,
'deltainfos' => \%deltainfos,
'appdatas' => $appdatas,
'patterns' => $patterns,
'dbgsplit' => $dbgsplit,
'packtrack' => $packtrack,
'repotags' => \@repotags,
};
if ($repotype{'rpm-md'}) {
createrepo_rpmmd($extrep, $projid, $xrepoid, $data, $repotype{'rpm-md'});
} else {
deleterepo_rpmmd($extrep, $projid, $xrepoid, $data);
}
if ($repotype{'suse'}) {
createrepo_susetags($extrep, $projid, $xrepoid, $data, $repotype{'suse'});
} else {
deleterepo_susetags($extrep, $projid, $xrepoid, $data);
}
# Mandriva format:
if ($repotype{'hdlist2'}) {
createrepo_hdlist2($extrep, $projid, $xrepoid, $data, $repotype{'hdlist2'});
} else {
deleterepo_hdlist2($extrep, $projid, $xrepoid, $data);
}
if ($repotype{'debian'}) {
createrepo_debian($extrep, $projid, $xrepoid, $data, $repotype{'debian'});
} else {
deleterepo_debian($extrep, $projid, $xrepoid, $data);
}
if ($repotype{'arch'}) {
createrepo_arch($extrep, $projid, $xrepoid, $data, $repotype{'arch'});
} else {
deleterepo_arch($extrep, $projid, $xrepoid, $data);
}
if ($repotype{'staticlinks'}) {
createrepo_staticlinks($extrep, $projid, $xrepoid, $data, $repotype{'staticlinks'});
} else {
deleterepo_staticlinks($extrep, $projid, $xrepoid, $data);
}
if ($patterntype{'ymp'}) {
createpatterns_ymp($extrep, $projid, $xrepoid, $data, $patterntype{'ymp'});
} else {
deletepatterns_ymp($extrep, $projid, $xrepoid, $data);
}
if ($patterntype{'rpm-md'}) {
createpatterns_rpmmd($extrep, $projid, $xrepoid, $data, $patterntype{'rpm-md'});
} else {
deletepatterns_rpmmd($extrep, $projid, $xrepoid, $data);
}
if ($patterntype{'comps'}) {
createpatterns_comps($extrep, $projid, $xrepoid, $data, $patterntype{'comps'});
} else {
deletepatterns_comps($extrep, $projid, $xrepoid, $data);
}
# virt-builder repository
if (-e "$extrep/index") {
createrepo_virtbuilder($extrep, $projid, $xrepoid, $data);
}
publishprog_done:
unlink("$uploaddir/publisher.$$") if $signkey;
# post process step: create directory listing for poor YaST
if ($repotype{'suse'}) {
unlink("$extrep/directory.yast");
my @d = sort(ls($extrep));
for (@d) {
$_ .= '/' if -d "$extrep/$_";
$_ .= "\n";
}
writestr("$extrep/.directory.yast", "$extrep/directory.yast", join('', @d));
}
# push the repo (unless there's a redirect)
# FIXME: use different mechanism to disable sync
if (!($BSConfig::publishredirect && $BSConfig::publishredirect->{$prp})) {
if ($extrep =~ /\Q$extrepodir\E\/(.+)$/) {
sync_to_stage($prp, $1, $dbgsplit);
}
}
# support for regex usage in $BSConfig::unpublishedhook
my $unpublish_prp = $prp;
if ($BSConfig::unpublishedhook_use_regex || $BSConfig::unpublishedhook_use_regex) {
for my $key (sort {$b cmp $a} keys %{$BSConfig::unpublishedhook}) {
if ($prp =~ /^$key/) {
$unpublish_prp = $key;
last;
}
}
}
if ($BSConfig::unpublishedhook && $BSConfig::unpublishedhook->{$unpublish_prp}) {
my $hook = $BSConfig::unpublishedhook->{$unpublish_prp};
$hook = [ $hook ] unless ref $hook;
print " calling unpublished hook @$hook\n";
qsystem(@$hook, $prp, $extrep, @db_deleted) && warn(" @$hook failed: $?\n");
}
# support for regex usage in $BSConfig::publishedhook
my $publish_prp = $prp;
if ($BSConfig::publishedhook_use_regex || $BSConfig::publishedhook_use_regex) {
for my $key (sort {$b cmp $a} keys %{$BSConfig::publishedhook}) {
if ($prp =~ /^$key/) {
$publish_prp = $key;
last;
}
}
}
if ($BSConfig::publishedhook && $BSConfig::publishedhook->{$publish_prp}) {
my $hook = $BSConfig::publishedhook->{$publish_prp};
$hook = [ $hook ] unless ref $hook;
print " calling published hook @$hook\n";
qsystem(@$hook, $prp, $extrep, @changed) && warn(" @$hook failed: $?\n");
}
BSNotify::notify('REPO_PUBLISHED', { project => $projid , 'repo' => $repoid });
# all done. till next time...
if ($BSConfig::publishprogram && $BSConfig::publishprogram->{$prp}) {
exit(0);
}
# recurse for dbgsplit
publish($projid, $repoid, $repoinfo->{'splitdebug'}, $packtrack) if $repoinfo->{'splitdebug'} && !$dbgsplit;
if ($packtrack && !$dbgsplit) {
# update the packtrack cache (and remove the 'id' entry)
my @newcache;
for my $pt (values %$packtrack) {
my $id = delete $pt->{'id'};
push @newcache, $id, [ map {$pt->{$_ eq 'arch' ? 'binaryarch' : $_}} qw{arch name epoch version release disturl buildtime} ] if $id;
}
$repoinfo = BSUtil::retrieve("$reporoot/$prp/:repoinfo", 1) || {};
if (%$repoinfo) {
$repoinfo->{'trackercache'} = \@newcache;
$repoinfo->{'trackercacheversion'} = '1';
BSUtil::store("$reporoot/$prp/.:repoinfo", "$reporoot/$prp/:repoinfo", $repoinfo);
@newcache = (); # free mem
undef $repoinfo; # free mem
}
# send notification
print " sending binary release tracking notification\n";
BSNotify::notify('PACKTRACK', { project => $projid , 'repo' => $repoid }, Storable::nfreeze([ map { $packtrack->{$_} } sort keys %$packtrack ]));
}
}
sub clear_repoinfo_state {
my ($prp) = @_;
if (-s "$reporoot/$prp/:repoinfo") {
my $repoinfo = BSUtil::retrieve("$reporoot/$prp/:repoinfo", 1) || {};
if ($repoinfo->{'state'}) {
delete $repoinfo->{'state'};
BSUtil::store("$reporoot/$prp/.:repoinfo", "$reporoot/$prp/:repoinfo", $repoinfo);
}
}
}
# check if background publish is still running
sub check_publish_prg_running {
my ($prp) = @_;
return 0 unless $BSConfig::publishprogram && $BSConfig::publishprogram->{$prp};
local *PPLOCK;
if (open(PPLOCK, '<', "$reporoot/$prp/.pplock")) {
if (flock(PPLOCK, LOCK_EX | LOCK_NB)) {
close PPLOCK;
return 1;
}
close PPLOCK;
}
return 0;
}
$| = 1;
$SIG{'PIPE'} = 'IGNORE';
BSUtil::restartexit($ARGV[0], 'publisher', "$rundir/bs_publish", "$myeventdir/.ping");
print "starting build service publisher\n";
mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_publish.lock") || die("$rundir/bs_publish.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("publisher is already running!\n");
utime undef, undef, "$rundir/bs_publish.lock";
mkdir_p($myeventdir);
if (!-p "$myeventdir/.ping") {
POSIX::mkfifo("$myeventdir/.ping", 0666) || die("$myeventdir/.ping: $!");
chmod(0666, "$myeventdir/.ping");
}
sysopen(PING, "$myeventdir/.ping", POSIX::O_RDWR) || die("$myeventdir/.ping: $!");
db_sync();
if (@ARGV && $ARGV[0] eq '--testmode') {
$testmode = 1;
shift @ARGV;
}
if (@ARGV > 1 && $ARGV[0] eq '--event') {
my $eventfile = $ARGV[1];
my $ev = readxml($eventfile, $BSXML::event);
die("not a publish event\n") if !$ev->{'type'} || $ev->{'type'} ne 'publish';
die("need a project and repository\n") unless defined($ev->{'project'}) && defined($ev->{'repository'});
my $prp = "$ev->{'project'}/$ev->{'repository'}";
die("$prp: external publish program still running\n") if check_publish_prg_running($prp);
rename($eventfile, "${eventfile}::inprogress");
BSNotify::notify('REPO_PUBLISH_STATE', { 'project' => $ev->{'project'}, 'repo' => $ev->{'repository'}, 'state' => 'publishing'} );
eval {
publish($ev->{'project'}, $ev->{'repository'});
};
if ($@) {
warn("publish failed for $ev->{'project'}, $ev->{'repository'} : $@");
clear_repoinfo_state($prp);
rename("${eventfile}::inprogress", $eventfile);
db_sync();
exit(1);
}
BSNotify::notify('REPO_PUBLISH_STATE', { 'project' => $ev->{'project'}, 'repo' => $ev->{'repository'}, 'state' => 'published'} );
db_sync();
unlink("${eventfile}::inprogress");
exit(0);
}
my %publish_retry;
my %publish_lasttime;
my %publish_duration;
while(1) {
# drain ping pipe
my $dummy;
fcntl(PING,F_SETFL,POSIX::O_NONBLOCK);
1 while (sysread(PING, $dummy, 1024, 0) || 0) > 0;
fcntl(PING,F_SETFL,0);
# check for events
my @events = ls($myeventdir);
# allows the admin to rename an event with a _ prefix to be the next event.
my @highprioevents = grep {/^_/} @events;
@events = grep {!/^[_\.]/} @events;
for my $event (@highprioevents, @events) {
next if $publish_retry{$event};
last if -e "$rundir/bs_publish.exit";
last if -e "$rundir/bs_publish.rescan";
last if -e "$rundir/bs_publish.restart";
my $ev = readxml("$myeventdir/$event", $BSXML::event, 1);
if ($ev && $ev->{'type'} eq 'configuration') {
print "updating configuration\n";
BSConfiguration::update_from_configuration();
}
if (!$ev || !$ev->{'type'} || $ev->{'type'} ne 'publish') {
unlink("$myeventdir/$event");
next;
}
if (!defined($ev->{'project'}) || !defined($ev->{'repository'})) {
unlink("$myeventdir/$event");
next;
}
my $prp = "$ev->{'project'}/$ev->{'repository'}";
if (check_publish_prg_running($prp)) {
print "$prp: external publish program still running\n";
$publish_retry{$event} = time() + 60;
next;
}
my $starttime = time();
if ($publish_lasttime{$prp} && $publish_duration{$prp} > 300 && $publish_lasttime{$prp} + 5 * $publish_duration{$prp} > $starttime) {
print "$prp: not yet\n";
$publish_retry{$event} = $starttime + 60 * 5;
next;
}
rename("$myeventdir/$event", "$myeventdir/${event}::inprogress");
BSNotify::notify('REPO_PUBLISH_STATE', { 'project' => $ev->{'project'}, 'repo' => $ev->{'repository'}, 'state' => 'publishing'} );
eval {
publish($ev->{'project'}, $ev->{'repository'});
};
if ($@) {
warn("publish failed for $ev->{'project'}, $ev->{'repository'} : $@");
# delete state from repoinfo so that we will always re-publish
clear_repoinfo_state($prp);
rename("$myeventdir/${event}::inprogress", "$myeventdir/$event");
$publish_retry{$event} = time() + 60;
db_sync();
} else {
my $now = time();
$publish_lasttime{$prp} = $now;
$publish_duration{$prp} = $now - $starttime;
BSNotify::notify('REPO_PUBLISH_STATE', { 'project' => $ev->{'project'}, 'repo' => $ev->{'repository'}, 'state' => 'published'} );
db_sync();
unlink("$myeventdir/${event}::inprogress");
}
}
# check for restart/exit
if (-e "$rundir/bs_publish.exit") {
close(RUNLOCK);
unlink("$rundir/bs_publish.exit");
print "exiting...\n";
exit(0);
}
if (-e "$rundir/bs_publish.restart") {
close(RUNLOCK);
unlink("$rundir/bs_publish.restart");
print "restarting...\n";
exec($0);
die("$0: $!\n");
}
if (-e "$rundir/bs_publish.rescan") {
unlink("$rundir/bs_publish.rescan");
}
if (%publish_retry) {
my $now = time();
for (sort keys %publish_retry) {
delete($publish_retry{$_}) if $publish_retry{$_} < $now;
}
print "sleeping 10 seconds...\n";
sleep(10);
} else {
if ($testmode) {
print "Test mode, all events processed, exiting...\n";
exit(0);
}
print "waiting for an event...\n";
sysread(PING, $dummy, 1, 0);
}
}
|