Fixes and updates for new FU version

This commit is contained in:
Yorhel 2025-02-28 13:55:57 +01:00
parent c16fe86e7a
commit 5cc77bc7f1
3 changed files with 25 additions and 21 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*~
/ManUtils/* /ManUtils/*
!/ManUtils/Makefile.PL !/ManUtils/Makefile.PL
!/ManUtils/ManUtils.pm !/ManUtils/ManUtils.pm

View file

@ -23,7 +23,7 @@ Ironically, documentation about how things work is completely lacking.
## File structure ## File structure
- **indexer/** -> The Rust program that scans package repositories for updates, fetches new packages and extracts the man pages. - **indexer/** -> The Rust program that scans package repositories for updates, fetches new packages and extracts the man pages.
- **lib/ManUtils/** -> Perl/XS helper module to format man pages into HTML (uses **web/**). - **ManUtils/** -> Perl/XS helper module to format man pages into HTML (uses **web/**).
- **sql/** -> Database schema & updates. - **sql/** -> Database schema & updates.
- **util/** -> Cron job and scripts to run **indexer/** on the right repositories. - **util/** -> Cron job and scripts to run **indexer/** on the right repositories.
- **web/** -> Badly named Rust library to convert man pages into HTML. - **web/** -> Badly named Rust library to convert man pages into HTML.

View file

@ -5,7 +5,7 @@ use FU -spawn;
use FU::SQL; use FU::SQL;
use FU::XMLWriter ':html5_'; use FU::XMLWriter ':html5_';
use FU::Util 'httpdate_format', 'uri_escape'; use FU::Util 'httpdate_format', 'uri_escape';
use POSIX 'ceil'; use POSIX 'ceil', 'strftime';
use List::Util 'uniq', 'min'; use List::Util 'uniq', 'min';
use Time::Local 'timegm'; use Time::Local 'timegm';
@ -17,7 +17,9 @@ use lib "$ROOT/ManUtils/blib/lib", "$ROOT/ManUtils/blib/arch";
use ManUtils; use ManUtils;
FU::init_db(''); # Must be configured through env vars # Database must be configured through env vars
FU::init_db(sub { FU::Pg->connect('')->set_type(bytea => '$hex') });
FU::debug_info('/fu-debug', 'debug~', 10);
FU::log_slow_reqs 500; FU::log_slow_reqs 500;
@ -28,10 +30,11 @@ FU::before_request {
}; };
# Set the last modification time from a string in yyyy-mm-dd format. sub fmtdate { strftime '%Y-%m-%d', gmtime $_[0] }
# Set the last modification time
sub FU::obj::set_lastmod($, $d) { sub FU::obj::set_lastmod($, $d) {
return if $d !~ /^(\d{4})-(\d{2})-(\d{2})/; fu->set_header('last-modified', httpdate_format $d) if $d;
fu->set_header('last-modified', httpdate_format timegm 0,0,0,$3,$2-1,$1);
} }
@ -727,7 +730,7 @@ sub soelim($verid, $src) {
sub man_page($man, $url) { sub man_page($man, $url) {
fu->set_lastmod($man->{released}); fu->set_lastmod($man->{released});
my($hash, $content) = fu->SQL('SELECT encode(hash, \'hex\') AS hash, content FROM contents WHERE id =', $man->{content})->rowl; my($hash, $content) = fu->SQL('SELECT hash, content FROM contents WHERE id =', $man->{content})->rowl;
if($url->{fmt} eq 'raw') { if($url->{fmt} eq 'raw') {
fu->set_header('content-type', 'text/plain'); fu->set_header('content-type', 'text/plain');
fu->set_header('content-disposition', sprintf 'filename="%s.%s"', $man->{name}, $man->{section}); fu->set_header('content-disposition', sprintf 'filename="%s.%s"', $man->{name}, $man->{section});
@ -786,7 +789,7 @@ FU::get qr{/([^/]+)(?:/([0-9a-f]{8}))?} => sub($name, $shorthash=undef) {
$name = normalize_name $name; $name = normalize_name $name;
my($man, $sect) = man_pref_name $name, $shorthash ? SQL 'f.shorthash =', shorthash_to_int $shorthash : 'true'; my($man, $sect) = man_pref_name $name, $shorthash ? SQL 'f.shorthash =', shorthash_to_int $shorthash : 'true';
fu->error(404) if !$man->{name}; fu->notfound if !$man->{name};
man_page $man, ManUrl->new( man_page $man, ManUrl->new(
fmt => 'man', fmt => 'man',
@ -801,7 +804,7 @@ FU::get qr{/([^/]+)/([0-9a-f]{8})/src} => sub($name, $shorthash) {
$name = normalize_name $name; $name = normalize_name $name;
my($man) = man_pref_name $name, SQL 'f.shorthash =', shorthash_to_int $shorthash; my($man) = man_pref_name $name, SQL 'f.shorthash =', shorthash_to_int $shorthash;
fu->error(404) if !$man->{name}; fu->notfound if !$man->{name};
man_page $man, ManUrl->new(fmt => 'raw', man => $name); man_page $man, ManUrl->new(fmt => 'raw', man => $name);
}; };
@ -815,12 +818,12 @@ FU::get qr{/(man|txt|raw)(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/(.+)} => sub($fmt
if($system) { if($system) {
my $sysid = sysbyshort->{$system}; my $sysid = sysbyshort->{$system};
$sysid = $sysid ? [$sysid->{id}] : [ map sysbyshort->{$_}{id}, grep /^\Q$system\E-/, keys sysbyshort->%* ]; $sysid = $sysid ? [$sysid->{id}] : [ map sysbyshort->{$_}{id}, grep /^\Q$system\E-/, keys sysbyshort->%* ];
fu->error(404) if !@$sysid; fu->notfound if !@$sysid;
push @where, SQL system => IN $sysid; push @where, SQL system => IN $sysid;
} }
my($pkg, $ver, $redir) = length $path ? pkg_frompath AND(@where), $path : (undef,undef); my($pkg, $ver, $redir) = length $path ? pkg_frompath AND(@where), $path : (undef,undef);
fu->error(404) if length $path && !$pkg; fu->notfound if length $path && !$pkg;
push @where, SQL 'p.id =', $pkg->{id} if $pkg; push @where, SQL 'p.id =', $pkg->{id} if $pkg;
push @where, SQL 'v.version =', $ver if length $ver; push @where, SQL 'v.version =', $ver if length $ver;
@ -828,7 +831,7 @@ FU::get qr{/(man|txt|raw)(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/(.+)} => sub($fmt
push @where, SQL 'l.locale =', $lang if $lang; push @where, SQL 'l.locale =', $lang if $lang;
my($man, $section) = man_pref_name $name, AND @where; my($man, $section) = man_pref_name $name, AND @where;
fu->error(404) if !$man; fu->notfound if !$man;
my $url = ManUrl->new( my $url = ManUrl->new(
fmt => $fmt, fmt => $fmt,
@ -847,7 +850,7 @@ FU::get qr{/(man|txt|raw)(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/(.+)} => sub($fmt
FU::get qr{/pkg/([^/]+)} => sub($short) { FU::get qr{/pkg/([^/]+)} => sub($short) {
my $sys = sysbyshort->{$short}; my $sys = sysbyshort->{$short};
fu->error(404) if !$sys; fu->notfound if !$sys;
$FU::REQ->{qs} =~ s/;/&/g if $FU::REQ->{qs}; # HACK: old URLs used ';' as separator instead of '&' $FU::REQ->{qs} =~ s/;/&/g if $FU::REQ->{qs}; # HACK: old URLs used ';' as separator instead of '&'
my $f = fu->query( my $f = fu->query(
@ -889,10 +892,10 @@ FU::get qr{/pkg/([^/]+)} => sub($short) {
# Package info: /pkg/$system[/$category]/$name[/$version]; $category and $name may contain slashes, too. # Package info: /pkg/$system[/$category]/$name[/$version]; $category and $name may contain slashes, too.
FU::get qr{/pkg/([^/]+)/(.+)} => sub($short, $path) { FU::get qr{/pkg/([^/]+)/(.+)} => sub($short, $path) {
my $sys = sysbyshort->{$short}; my $sys = sysbyshort->{$short};
fu->error(404) if !$sys; fu->notfound if !$sys;
my($pkg, $ver, $redir) = pkg_frompath(SQL('system =', $sys->{id}), $path); my($pkg, $ver, $redir) = pkg_frompath(SQL('system =', $sys->{id}), $path);
fu->error(404) if !$pkg; fu->notfound if !$pkg;
fu->redirect(perm => "/pkg/$short/$pkg->{name}".($ver?"/$ver":'')) if $redir; fu->redirect(perm => "/pkg/$short/$pkg->{name}".($ver?"/$ver":'')) if $redir;
my $vers = fu->SQL(' my $vers = fu->SQL('
@ -903,7 +906,7 @@ FU::get qr{/pkg/([^/]+)/(.+)} => sub($short, $path) {
ORDER BY released DESC' ORDER BY released DESC'
)->allh; )->allh;
my $sel = $ver ? (grep $_->{version} eq $ver, @$vers)[0] : $vers->[0]; my $sel = $ver ? (grep $_->{version} eq $ver, @$vers)[0] : $vers->[0];
fu->error(404) if !$sel; fu->notfound if !$sel;
my $p = fu->query(p => { onerror => 1, uint => 1, range => [1,100] }); my $p = fu->query(p => { onerror => 1, uint => 1, range => [1,100] });
@ -945,7 +948,7 @@ FU::get qr{/pkg/([^/]+)/(.+)} => sub($short, $path) {
li_ sub { li_ sub {
a_ href => "/pkg/$pkgpath/$_->{version}", $_->{version} if $_ != $sel; a_ href => "/pkg/$pkgpath/$_->{version}", $_->{version} if $_ != $sel;
b_ " $_->{version}" if $_ == $sel; b_ " $_->{version}" if $_ == $sel;
small_ " $_->{released}"; small_ ' '.fmtdate $_->{released};
} for(@$vers); } for(@$vers);
} }
}; };
@ -993,11 +996,11 @@ FU::get qr{/loc/([a-fA-F0-9]{40})}, sub($hash) {
JOIN mans m ON m.id = f.man JOIN mans m ON m.id = f.man
JOIN package_versions v ON v.id = f.pkgver JOIN package_versions v ON v.id = f.pkgver
JOIN packages p ON p.id = v.package JOIN packages p ON p.id = v.package
WHERE f.content = (SELECT id FROM contents WHERE hash = decode(', $hash, ", 'hex')) WHERE f.content = (SELECT id FROM contents WHERE hash =', $hash, ')
ORDER BY p.system DESC, p.name, v.released DESC, f.filename ORDER BY p.system DESC, p.name, v.released DESC, f.filename
LIMIT ", $maxlisting LIMIT ', $maxlisting
)->allh; )->allh;
fu->error(404) if !@$l; fu->notfound if !@$l;
my %sys; my %sys;
push $sys{ sysbyid->{$_->{system}}{name} }->@*, $_ for @$l; push $sys{ sysbyid->{$_->{system}}{name} }->@*, $_ for @$l;
@ -1138,7 +1141,7 @@ FU::get qr{/ver(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/([^/]+)\.([0-9a-zA-Z]+)}, s
td_ sub { td_ sub {
a_ href => "/pkg/$sys->{short}/$_->{package}/$_->{version}", $_->{package}.'-'.$_->{version}; a_ href => "/pkg/$sys->{short}/$_->{package}/$_->{version}", $_->{package}.'-'.$_->{version};
}; };
td_ $_->{released}; td_ fmtdate $_->{released};
td_ class => 'sh', sub { td_ class => 'sh', sub {
my $hex = shorthash_to_hex $_->{shorthash}; my $hex = shorthash_to_hex $_->{shorthash};
txt_ $hex if $_->{shorthash} == $shorthash; txt_ $hex if $_->{shorthash} == $shorthash;