From 253a86b7bf4a3d81118e91f4ebb77844cfbd2b32 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 4 Feb 2020 04:44:25 +0000 Subject: over: simplify read-only vs read-write checking No need to call ref() and do a string comparison. Add some extra tests using the {ReadOnly} attribute in DBI.pm. --- lib/PublicInbox/Over.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/Over.pm') diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm index 0f8f433a..57c82bfc 100644 --- a/lib/PublicInbox/Over.pm +++ b/lib/PublicInbox/Over.pm @@ -14,17 +14,16 @@ use Compress::Zlib qw(uncompress); use constant DEFAULT_LIMIT => 1000; sub dbh_new { - my ($self) = @_; - my $ro = ref($self) eq 'PublicInbox::Over'; + my ($self, $rw) = @_; my $f = $self->{filename}; - if (!$ro && !-f $f) { # SQLite defaults mode to 0644, we want 0666 + if ($rw && !-f $f) { # SQLite defaults mode to 0644, we want 0666 open my $fh, '+>>', $f or die "failed to open $f: $!"; } my $dbh = DBI->connect("dbi:SQLite:dbname=$f",'','', { AutoCommit => 1, RaiseError => 1, PrintError => 0, - ReadOnly => $ro, + ReadOnly => !$rw, sqlite_use_immediate_transaction => 1, }); $dbh->{sqlite_unicode} = 1; -- cgit v1.2.3-24-ge0c7