summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/aggregate.pm
blob: e000bc8648a39f33cea5aef932286255f343f4a2 (plain)
  1. #!/usr/bin/perl
  2. # Feed aggregation plugin.
  3. package IkiWiki::Plugin::aggregate;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. use HTML::Parser;
  8. use HTML::Tagset;
  9. use HTML::Entities;
  10. use URI;
  11. use open qw{:utf8 :std};
  12. my %feeds;
  13. my %guids;
  14. sub import { #{{{
  15. hook(type => "getopt", id => "aggregate", call => \&getopt);
  16. hook(type => "checkconfig", id => "aggregate", call => \&checkconfig);
  17. hook(type => "needsbuild", id => "aggregate", call => \&needsbuild);
  18. hook(type => "preprocess", id => "aggregate", call => \&preprocess);
  19. hook(type => "delete", id => "aggregate", call => \&delete);
  20. hook(type => "savestate", id => "aggregate", call => \&savestate);
  21. hook(type => "htmlize", id => "_aggregated", call => \&htmlize);
  22. if (exists $config{aggregate_webtrigger} && $config{aggregate_webtrigger}) {
  23. hook(type => "cgi", id => "aggregate", call => \&cgi);
  24. }
  25. } # }}}
  26. sub getopt () { #{{{
  27. eval q{use Getopt::Long};
  28. error($@) if $@;
  29. Getopt::Long::Configure('pass_through');
  30. GetOptions(
  31. "aggregate" => \$config{aggregate},
  32. "aggregateinternal!" => \$config{aggregateinternal},
  33. );
  34. } #}}}
  35. sub checkconfig () { #{{{
  36. if ($config{aggregate} && ! ($config{post_commit} &&
  37. IkiWiki::commit_hook_enabled())) {
  38. launchaggregation();
  39. }
  40. } #}}}
  41. sub cgi ($) { #{{{
  42. my $cgi=shift;
  43. if (defined $cgi->param('do') &&
  44. $cgi->param("do") eq "aggregate_webtrigger") {
  45. $|=1;
  46. print "Content-Type: text/plain\n\n";
  47. $config{cgi}=0;
  48. $config{verbose}=1;
  49. $config{syslog}=0;
  50. print gettext("Aggregation triggered via web.")."\n\n";
  51. if (launchaggregation()) {
  52. IkiWiki::lockwiki();
  53. IkiWiki::loadindex();
  54. require IkiWiki::Render;
  55. IkiWiki::refresh();
  56. IkiWiki::saveindex();
  57. }
  58. else {
  59. print gettext("Nothing to do right now, all feeds are up-to-date!")."\n";
  60. }
  61. exit 0;
  62. }
  63. } #}}}
  64. sub launchaggregation () { #{{{
  65. # See if any feeds need aggregation.
  66. loadstate();
  67. my @feeds=needsaggregate();
  68. return unless @feeds;
  69. if (! lockaggregate()) {
  70. debug("an aggregation process is already running");
  71. return;
  72. }
  73. # force a later rebuild of source pages
  74. $IkiWiki::forcerebuild{$_->{sourcepage}}=1
  75. foreach @feeds;
  76. # Fork a child process to handle the aggregation.
  77. # The parent process will then handle building the
  78. # result. This avoids messy code to clear state
  79. # accumulated while aggregating.
  80. defined(my $pid = fork) or error("Can't fork: $!");
  81. if (! $pid) {
  82. IkiWiki::loadindex();
  83. # Aggregation happens without the main wiki lock
  84. # being held. This allows editing pages etc while
  85. # aggregation is running.
  86. aggregate(@feeds);
  87. IkiWiki::lockwiki;
  88. # Merge changes, since aggregation state may have
  89. # changed on disk while the aggregation was happening.
  90. mergestate();
  91. expire();
  92. savestate();
  93. IkiWiki::unlockwiki;
  94. exit 0;
  95. }
  96. waitpid($pid,0);
  97. if ($?) {
  98. error "aggregation failed with code $?";
  99. }
  100. clearstate();
  101. unlockaggregate();
  102. return 1;
  103. } #}}}
  104. # Pages with extension _aggregated have plain html markup, pass through.
  105. sub htmlize (@) { #{{{
  106. my %params=@_;
  107. return $params{content};
  108. } #}}}
  109. # Used by ikiwiki-transition aggregateinternal.
  110. sub migrate_to_internal { #{{{
  111. if (! lockaggregate()) {
  112. error("an aggregation process is currently running");
  113. }
  114. IkiWiki::lockwiki();
  115. loadstate();
  116. $config{verbose}=1;
  117. foreach my $data (values %guids) {
  118. next unless $data->{page};
  119. next if $data->{expired};
  120. $config{aggregateinternal} = 0;
  121. my $oldname = pagefile($data->{page});
  122. my $oldoutput = $config{destdir}."/".IkiWiki::htmlpage($data->{page});
  123. $config{aggregateinternal} = 1;
  124. my $newname = pagefile($data->{page});
  125. debug "moving $oldname -> $newname";
  126. if (-e $newname) {
  127. if (-e $oldname) {
  128. error("$newname already exists");
  129. }
  130. else {
  131. debug("already renamed to $newname?");
  132. }
  133. }
  134. elsif (-e $oldname) {
  135. rename($oldname, $newname) || error("$!");
  136. }
  137. else {
  138. debug("$oldname not found");
  139. }
  140. if (-e $oldoutput) {
  141. require IkiWiki::Render;
  142. debug("removing output file $oldoutput");
  143. IkiWiki::prune($oldoutput);
  144. }
  145. }
  146. savestate();
  147. IkiWiki::unlockwiki;
  148. unlockaggregate();
  149. } #}}}
  150. sub needsbuild (@) { #{{{
  151. my $needsbuild=shift;
  152. loadstate();
  153. foreach my $feed (values %feeds) {
  154. if (exists $pagesources{$feed->{sourcepage}} &&
  155. grep { $_ eq $pagesources{$feed->{sourcepage}} } @$needsbuild) {
  156. # Mark all feeds originating on this page as
  157. # not yet seen; preprocess will unmark those that
  158. # still exist.
  159. markunseen($feed->{sourcepage});
  160. }
  161. }
  162. } # }}}
  163. sub preprocess (@) { #{{{
  164. my %params=@_;
  165. foreach my $required (qw{name url}) {
  166. if (! exists $params{$required}) {
  167. error sprintf(gettext("missing %s parameter"), $required)
  168. }
  169. }
  170. my $feed={};
  171. my $name=$params{name};
  172. if (exists $feeds{$name}) {
  173. $feed=$feeds{$name};
  174. }
  175. else {
  176. $feeds{$name}=$feed;
  177. }
  178. $feed->{name}=$name;
  179. $feed->{sourcepage}=$params{page};
  180. $feed->{url}=$params{url};
  181. my $dir=exists $params{dir} ? $params{dir} : $params{page}."/".IkiWiki::titlepage($params{name});
  182. $dir=~s/^\/+//;
  183. ($dir)=$dir=~/$config{wiki_file_regexp}/;
  184. $feed->{dir}=$dir;
  185. $feed->{feedurl}=defined $params{feedurl} ? $params{feedurl} : "";
  186. $feed->{updateinterval}=defined $params{updateinterval} ? $params{updateinterval} * 60 : 15 * 60;
  187. $feed->{expireage}=defined $params{expireage} ? $params{expireage} : 0;
  188. $feed->{expirecount}=defined $params{expirecount} ? $params{expirecount} : 0;
  189. if (exists $params{template}) {
  190. $params{template}=~s/[^-_a-zA-Z0-9]+//g;
  191. }
  192. else {
  193. $params{template} = "aggregatepost"
  194. }
  195. $feed->{template}=$params{template} . ".tmpl";
  196. delete $feed->{unseen};
  197. $feed->{lastupdate}=0 unless defined $feed->{lastupdate};
  198. $feed->{numposts}=0 unless defined $feed->{numposts};
  199. $feed->{newposts}=0 unless defined $feed->{newposts};
  200. $feed->{message}=gettext("new feed") unless defined $feed->{message};
  201. $feed->{error}=0 unless defined $feed->{error};
  202. $feed->{tags}=[];
  203. while (@_) {
  204. my $key=shift;
  205. my $value=shift;
  206. if ($key eq 'tag') {
  207. push @{$feed->{tags}}, $value;
  208. }
  209. }
  210. return "<a href=\"".$feed->{url}."\">".$feed->{name}."</a>: ".
  211. ($feed->{error} ? "<em>" : "").$feed->{message}.
  212. ($feed->{error} ? "</em>" : "").
  213. " (".$feed->{numposts}." ".gettext("posts").
  214. ($feed->{newposts} ? "; ".$feed->{newposts}.
  215. " ".gettext("new") : "").
  216. ")";
  217. } # }}}
  218. sub delete (@) { #{{{
  219. my @files=@_;
  220. # Remove feed data for removed pages.
  221. foreach my $file (@files) {
  222. my $page=pagename($file);
  223. markunseen($page);
  224. }
  225. } #}}}
  226. sub markunseen ($) { #{{{
  227. my $page=shift;
  228. foreach my $id (keys %feeds) {
  229. if ($feeds{$id}->{sourcepage} eq $page) {
  230. $feeds{$id}->{unseen}=1;
  231. }
  232. }
  233. } #}}}
  234. my $state_loaded=0;
  235. sub loadstate () { #{{{
  236. return if $state_loaded;
  237. $state_loaded=1;
  238. if (-e "$config{wikistatedir}/aggregate") {
  239. open(IN, "$config{wikistatedir}/aggregate") ||
  240. die "$config{wikistatedir}/aggregate: $!";
  241. while (<IN>) {
  242. $_=IkiWiki::possibly_foolish_untaint($_);
  243. chomp;
  244. my $data={};
  245. foreach my $i (split(/ /, $_)) {
  246. my ($field, $val)=split(/=/, $i, 2);
  247. if ($field eq "name" || $field eq "feed" ||
  248. $field eq "guid" || $field eq "message") {
  249. $data->{$field}=decode_entities($val, " \t\n");
  250. }
  251. elsif ($field eq "tag") {
  252. push @{$data->{tags}}, $val;
  253. }
  254. else {
  255. $data->{$field}=$val;
  256. }
  257. }
  258. if (exists $data->{name}) {
  259. $feeds{$data->{name}}=$data;
  260. }
  261. elsif (exists $data->{guid}) {
  262. $guids{$data->{guid}}=$data;
  263. }
  264. }
  265. close IN;
  266. }
  267. } #}}}
  268. sub savestate () { #{{{
  269. return unless $state_loaded;
  270. garbage_collect();
  271. my $newfile="$config{wikistatedir}/aggregate.new";
  272. my $cleanup = sub { unlink($newfile) };
  273. open (OUT, ">$newfile") || error("open $newfile: $!", $cleanup);
  274. foreach my $data (values %feeds, values %guids) {
  275. my @line;
  276. foreach my $field (keys %$data) {
  277. if ($field eq "name" || $field eq "feed" ||
  278. $field eq "guid" || $field eq "message") {
  279. push @line, "$field=".encode_entities($data->{$field}, " \t\n");
  280. }
  281. elsif ($field eq "tags") {
  282. push @line, "tag=$_" foreach @{$data->{tags}};
  283. }
  284. else {
  285. push @line, "$field=".$data->{$field};
  286. }
  287. }
  288. print OUT join(" ", @line)."\n" || error("write $newfile: $!", $cleanup);
  289. }
  290. close OUT || error("save $newfile: $!", $cleanup);
  291. rename($newfile, "$config{wikistatedir}/aggregate") ||
  292. error("rename $newfile: $!", $cleanup);
  293. } #}}}
  294. sub garbage_collect () { #{{{
  295. foreach my $name (keys %feeds) {
  296. # remove any feeds that were not seen while building the pages
  297. # that used to contain them
  298. if ($feeds{$name}->{unseen}) {
  299. delete $feeds{$name};
  300. }
  301. }
  302. foreach my $guid (values %guids) {
  303. # any guid whose feed is gone should be removed
  304. if (! exists $feeds{$guid->{feed}}) {
  305. unlink pagefile($guid->{page})
  306. if exists $guid->{page};
  307. delete $guids{$guid->{guid}};
  308. }
  309. # handle expired guids
  310. elsif ($guid->{expired} && exists $guid->{page}) {
  311. unlink pagefile($guid->{page});
  312. delete $guid->{page};
  313. delete $guid->{md5};
  314. }
  315. }
  316. } #}}}
  317. sub mergestate () { #{{{
  318. # Load the current state in from disk, and merge into it
  319. # values from the state in memory that might have changed
  320. # during aggregation.
  321. my %myfeeds=%feeds;
  322. my %myguids=%guids;
  323. clearstate();
  324. loadstate();
  325. # All that can change in feed state during aggregation is a few
  326. # fields.
  327. foreach my $name (keys %myfeeds) {
  328. if (exists $feeds{$name}) {
  329. foreach my $field (qw{message lastupdate numposts
  330. newposts error}) {
  331. $feeds{$name}->{$field}=$myfeeds{$name}->{$field};
  332. }
  333. }
  334. }
  335. # New guids can be created during aggregation.
  336. # It's also possible that guids were removed from the on-disk state
  337. # while the aggregation was in process. That would only happen if
  338. # their feed was also removed, so any removed guids added back here
  339. # will be garbage collected later.
  340. foreach my $guid (keys %myguids) {
  341. if (! exists $guids{$guid}) {
  342. $guids{$guid}=$myguids{$guid};
  343. }
  344. }
  345. } #}}}
  346. sub clearstate () { #{{{
  347. %feeds=();
  348. %guids=();
  349. $state_loaded=0;
  350. } #}}}
  351. sub expire () { #{{{
  352. foreach my $feed (values %feeds) {
  353. next unless $feed->{expireage} || $feed->{expirecount};
  354. my $count=0;
  355. my %seen;
  356. foreach my $item (sort { $IkiWiki::pagectime{$b->{page}} <=> $IkiWiki::pagectime{$a->{page}} }
  357. grep { exists $_->{page} && $_->{feed} eq $feed->{name} && $IkiWiki::pagectime{$_->{page}} }
  358. values %guids) {
  359. if ($feed->{expireage}) {
  360. my $days_old = (time - $IkiWiki::pagectime{$item->{page}}) / 60 / 60 / 24;
  361. if ($days_old > $feed->{expireage}) {
  362. debug(sprintf(gettext("expiring %s (%s days old)"),
  363. $item->{page}, int($days_old)));
  364. $item->{expired}=1;
  365. }
  366. }
  367. elsif ($feed->{expirecount} &&
  368. $count >= $feed->{expirecount}) {
  369. debug(sprintf(gettext("expiring %s"), $item->{page}));
  370. $item->{expired}=1;
  371. }
  372. else {
  373. if (! $seen{$item->{page}}) {
  374. $seen{$item->{page}}=1;
  375. $count++;
  376. }
  377. }
  378. }
  379. }
  380. } #}}}
  381. sub needsaggregate () { #{{{
  382. return values %feeds if $config{rebuild};
  383. return grep { time - $_->{lastupdate} >= $_->{updateinterval} } values %feeds;
  384. } #}}}
  385. sub aggregate (@) { #{{{
  386. eval q{use XML::Feed};
  387. error($@) if $@;
  388. eval q{use URI::Fetch};
  389. error($@) if $@;
  390. foreach my $feed (@_) {
  391. $feed->{lastupdate}=time;
  392. $feed->{newposts}=0;
  393. $feed->{message}=sprintf(gettext("processed ok at %s"),
  394. displaytime($feed->{lastupdate}));
  395. $feed->{error}=0;
  396. debug(sprintf(gettext("checking feed %s ..."), $feed->{name}));
  397. if (! length $feed->{feedurl}) {
  398. my @urls=XML::Feed->find_feeds($feed->{url});
  399. if (! @urls) {
  400. $feed->{message}=sprintf(gettext("could not find feed at %s"), $feed->{url});
  401. $feed->{error}=1;
  402. debug($feed->{message});
  403. next;
  404. }
  405. $feed->{feedurl}=pop @urls;
  406. }
  407. my $res=URI::Fetch->fetch($feed->{feedurl});
  408. if (! $res) {
  409. $feed->{message}=URI::Fetch->errstr;
  410. $feed->{error}=1;
  411. debug($feed->{message});
  412. next;
  413. }
  414. if ($res->status == URI::Fetch::URI_GONE()) {
  415. $feed->{message}=gettext("feed not found");
  416. $feed->{error}=1;
  417. debug($feed->{message});
  418. next;
  419. }
  420. my $content=$res->content;
  421. my $f=eval{XML::Feed->parse(\$content)};
  422. if ($@) {
  423. # One common cause of XML::Feed crashing is a feed
  424. # that contains invalid UTF-8 sequences. Convert
  425. # feed to ascii to try to work around.
  426. $feed->{message}.=" ".sprintf(gettext("(invalid UTF-8 stripped from feed)"));
  427. $content=Encode::decode_utf8($content, 0);
  428. $f=eval{XML::Feed->parse(\$content)};
  429. }
  430. if ($@) {
  431. # Another possibility is badly escaped entities.
  432. $feed->{message}.=" ".sprintf(gettext("(feed entities escaped)"));
  433. $content=~s/\&(?!amp)(\w+);/&amp;$1;/g;
  434. $content=Encode::decode_utf8($content, 0);
  435. $f=eval{XML::Feed->parse(\$content)};
  436. }
  437. if ($@) {
  438. $feed->{message}=gettext("feed crashed XML::Feed!")." ($@)";
  439. $feed->{error}=1;
  440. debug($feed->{message});
  441. next;
  442. }
  443. if (! $f) {
  444. $feed->{message}=XML::Feed->errstr;
  445. $feed->{error}=1;
  446. debug($feed->{message});
  447. next;
  448. }
  449. foreach my $entry ($f->entries) {
  450. add_page(
  451. feed => $feed,
  452. copyright => $f->copyright,
  453. title => defined $entry->title ? decode_entities($entry->title) : "untitled",
  454. link => $entry->link,
  455. content => defined $entry->content->body ? $entry->content->body : "",
  456. guid => defined $entry->id ? $entry->id : time."_".$feed->{name},
  457. ctime => $entry->issued ? ($entry->issued->epoch || time) : time,
  458. );
  459. }
  460. }
  461. } #}}}
  462. sub add_page (@) { #{{{
  463. my %params=@_;
  464. my $feed=$params{feed};
  465. my $guid={};
  466. my $mtime;
  467. if (exists $guids{$params{guid}}) {
  468. # updating an existing post
  469. $guid=$guids{$params{guid}};
  470. return if $guid->{expired};
  471. }
  472. else {
  473. # new post
  474. $guid->{guid}=$params{guid};
  475. $guids{$params{guid}}=$guid;
  476. $mtime=$params{ctime};
  477. $feed->{numposts}++;
  478. $feed->{newposts}++;
  479. # assign it an unused page
  480. my $page=IkiWiki::titlepage($params{title});
  481. # escape slashes and periods in title so it doesn't specify
  482. # directory name or trigger ".." disallowing code.
  483. $page=~s!([/.])!"__".ord($1)."__"!eg;
  484. $page=$feed->{dir}."/".$page;
  485. ($page)=$page=~/$config{wiki_file_regexp}/;
  486. if (! defined $page || ! length $page) {
  487. $page=$feed->{dir}."/item";
  488. }
  489. my $c="";
  490. while (exists $IkiWiki::pagecase{lc $page.$c} ||
  491. -e pagefile($page.$c)) {
  492. $c++
  493. }
  494. # Make sure that the file name isn't too long.
  495. # NB: This doesn't check for path length limits.
  496. my $max=POSIX::pathconf($config{srcdir}, &POSIX::_PC_NAME_MAX);
  497. if (defined $max && length(htmlfn($page)) >= $max) {
  498. $c="";
  499. $page=$feed->{dir}."/item";
  500. while (exists $IkiWiki::pagecase{lc $page.$c} ||
  501. -e pagefile($page.$c)) {
  502. $c++
  503. }
  504. }
  505. $guid->{page}=$page;
  506. debug(sprintf(gettext("creating new page %s"), $page));
  507. }
  508. $guid->{feed}=$feed->{name};
  509. # To write or not to write? Need to avoid writing unchanged pages
  510. # to avoid unneccessary rebuilding. The mtime from rss cannot be
  511. # trusted; let's use a digest.
  512. eval q{use Digest::MD5 'md5_hex'};
  513. error($@) if $@;
  514. require Encode;
  515. my $digest=md5_hex(Encode::encode_utf8($params{content}));
  516. return unless ! exists $guid->{md5} || $guid->{md5} ne $digest || $config{rebuild};
  517. $guid->{md5}=$digest;
  518. # Create the page.
  519. my $template=template($feed->{template}, blind_cache => 1);
  520. $template->param(title => $params{title})
  521. if defined $params{title} && length($params{title});
  522. $template->param(content => htmlescape(htmlabs($params{content}, $feed->{feedurl})));
  523. $template->param(name => $feed->{name});
  524. $template->param(url => $feed->{url});
  525. $template->param(copyright => $params{copyright})
  526. if defined $params{copyright} && length $params{copyright};
  527. $template->param(permalink => urlabs($params{link}, $feed->{feedurl}))
  528. if defined $params{link};
  529. if (ref $feed->{tags}) {
  530. $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
  531. }
  532. writefile(htmlfn($guid->{page}), $config{srcdir},
  533. $template->output);
  534. # Set the mtime, this lets the build process get the right creation
  535. # time on record for the new page.
  536. utime $mtime, $mtime, pagefile($guid->{page})
  537. if defined $mtime && $mtime <= time;
  538. } #}}}
  539. sub htmlescape ($) { #{{{
  540. # escape accidental wikilinks and preprocessor stuff
  541. my $html=shift;
  542. $html=~s/(?<!\\)\[\[/\\\[\[/g;
  543. return $html;
  544. } #}}}
  545. sub urlabs ($$) { #{{{
  546. my $url=shift;
  547. my $urlbase=shift;
  548. URI->new_abs($url, $urlbase)->as_string;
  549. } #}}}
  550. sub htmlabs ($$) { #{{{
  551. # Convert links in html from relative to absolute.
  552. # Note that this is a heuristic, which is not specified by the rss
  553. # spec and may not be right for all feeds. Also, see Debian
  554. # bug #381359.
  555. my $html=shift;
  556. my $urlbase=shift;
  557. my $ret="";
  558. my $p = HTML::Parser->new(api_version => 3);
  559. $p->handler(default => sub { $ret.=join("", @_) }, "text");
  560. $p->handler(start => sub {
  561. my ($tagname, $pos, $text) = @_;
  562. if (ref $HTML::Tagset::linkElements{$tagname}) {
  563. while (4 <= @$pos) {
  564. # use attribute sets from right to left
  565. # to avoid invalidating the offsets
  566. # when replacing the values
  567. my($k_offset, $k_len, $v_offset, $v_len) =
  568. splice(@$pos, -4);
  569. my $attrname = lc(substr($text, $k_offset, $k_len));
  570. next unless grep { $_ eq $attrname } @{$HTML::Tagset::linkElements{$tagname}};
  571. next unless $v_offset; # 0 v_offset means no value
  572. my $v = substr($text, $v_offset, $v_len);
  573. $v =~ s/^([\'\"])(.*)\1$/$2/;
  574. my $new_v=urlabs($v, $urlbase);
  575. $new_v =~ s/\"/&quot;/g; # since we quote with ""
  576. substr($text, $v_offset, $v_len) = qq("$new_v");
  577. }
  578. }
  579. $ret.=$text;
  580. }, "tagname, tokenpos, text");
  581. $p->parse($html);
  582. $p->eof;
  583. return $ret;
  584. } #}}}
  585. sub pagefile ($) { #{{{
  586. my $page=shift;
  587. return "$config{srcdir}/".htmlfn($page);
  588. } #}}}
  589. sub htmlfn ($) { #{{{
  590. return shift().".".($config{aggregateinternal} ? "_aggregated" : $config{htmlext});
  591. } #}}}
  592. my $aggregatelock;
  593. sub lockaggregate () { #{{{
  594. # Take an exclusive lock to prevent multiple concurrent aggregators.
  595. # Returns true if the lock was aquired.
  596. if (! -d $config{wikistatedir}) {
  597. mkdir($config{wikistatedir});
  598. }
  599. open($aggregatelock, '>', "$config{wikistatedir}/aggregatelock") ||
  600. error ("cannot open to $config{wikistatedir}/aggregatelock: $!");
  601. if (! flock($aggregatelock, 2 | 4)) { # LOCK_EX | LOCK_NB
  602. close($aggregatelock) || error("failed closing aggregatelock: $!");
  603. return 0;
  604. }
  605. return 1;
  606. } #}}}
  607. sub unlockaggregate () { #{{{
  608. return close($aggregatelock) if $aggregatelock;
  609. return;
  610. } #}}}
  611. 1