On Tue, Nov 19, 2019 at 07:50:19PM +0100, Charlene Wendling wrote:
> On Mon, 18 Nov 2019 19:31:02 -0800
> Andrew Hewus Fresh wrote:
> 
> > On Mon, Nov 18, 2019 at 01:23:49PM +0100, Charlene Wendling wrote:
> > > Hi,
> > > 
> > > As i'm working on portgen(1) and remembered Pamela's manpage diff,
> > > i've found out that sqlports-compact is mentioned, and its presence
> > > still checked. I'm proposing to remove those bits.
> > > 
> > > It has been successfully tried in a chroot without sqlports
> > > installed, and the runtime is as expected on installed.
> > > 
> > > Comments/feedback are welcome,
> >  
> > I think we can clean this up even more since we know exactly what
> > we're working with now.  What do you think of this adjustment?
> 
> I like this diff. I guess it's fine to not put an error message handler
> for DBI given it would require careful changes in many places.
> 
> OK cwen@

I can instead move the `require DBI` down below the check for `-e
$dbfile`, which would avoid the eval and mess.  I think I will do just
that.  Although that will have to get reworked if we ever decide to
look at unveil + pledge for this.


 
> > Index: infrastructure/lib/OpenBSD/PortGen/Utils.pm
> > ===================================================================
> > RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Utils.pm,v
> > retrieving revision 1.3
> > diff -u -p -r1.3 Utils.pm
> > --- infrastructure/lib/OpenBSD/PortGen/Utils.pm     11 May 2019
> > 15:09:06 -0000      1.3 +++
> > infrastructure/lib/OpenBSD/PortGen/Utils.pm 19 Nov 2019
> > 03:28:44 -0000 @@ -19,7 +19,10 @@ package OpenBSD::PortGen::Utils;
> > use 5.012; use warnings;
> >  
> > -use DBI;
> > +# Optionally require DBI.
> > +# We'll get a better error message later if we need it.
> > +{ local $@; eval { local $SIG{__DIE__};
> > +    require DBI } };
> >  
> >  use parent qw( Exporter );
> >  
> > @@ -55,33 +58,17 @@ sub module_in_ports
> >  
> >     return unless $module and $prefix;
> >  
> > -   my $dbpath = '/usr/local/share';
> > -   my $dbfile;
> > +   my $dbfile = '/usr/local/share/sqlports';
> > +   die "install databases/sqlports\n" unless -e $dbfile;
> >  
> > -   if ( -e "$dbpath/sqlports-compact" ) {
> > -           $dbfile = 'sqlports-compact';
> > -   } elsif ( -e "$dbpath/sqlports" ) {
> > -           $dbfile = 'sqlports';
> > -   } else {
> > -           die "install databases/sqlports-compact or
> > databases/sqlports";
> > -   }
> > -
> > -   my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbpath/$dbfile",
> > "", "" )
> > -       or die "failed to connect to database: $DBI::errstr";
> > -
> > -   my $stmt;
> > -   $stmt =
> > -       $dbfile =~ /compact/
> > -       ? "SELECT FULLPKGPATH FROM Paths WHERE ID IN ( SELECT
> > FULLPKGPATH FROM Ports WHERE DISTNAME LIKE '$module%' )"
> > -       : "SELECT FULLPKGPATH FROM Ports WHERE DISTNAME LIKE
> > '$module%'"; -
> > -   my $pr = $dbh->prepare($stmt);
> > -   $pr->execute();
> > -
> > -   my @results;
> > -   while ( my @pkgpaths = $pr->fetchrow_array ) {
> > -           push @results, $pkgpaths[0];
> > -   }
> > +   my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "",
> > {
> > +       RaiseError => 1,
> > +   } ) or die "failed to connect to database: $DBI::errstr";
> > +
> > +   my @results = @{ $dbh->selectcol_arrayref(
> > +       "SELECT FULLPKGPATH FROM Ports WHERE DISTNAME LIKE ?",
> > +       {}, "$module%"
> > +   ) };
> >  
> >     $dbh->disconnect();
> > 
> 

-- 
andrew - http://afresh1.com

Speed matters.  
Almost as much as some things, and nowhere near as much as others.
                      -- Nick Holland

Reply via email to