* [PATCH 5/5] over: simplify read-only vs read-write checking
2020-02-04 4:44 5% [PATCH 0/5] a few more minor fixups Eric Wong
@ 2020-02-04 4:44 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-02-04 4:44 UTC (permalink / raw)
To: meta
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 +++----
lib/PublicInbox/OverIdx.pm | 2 +-
t/over.t | 7 ++++++-
3 files changed, 10 insertions(+), 6 deletions(-)
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;
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 5f1007aa..a966a710 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -20,7 +20,7 @@ use PublicInbox::Search;
sub dbh_new {
my ($self) = @_;
- my $dbh = $self->SUPER::dbh_new;
+ my $dbh = $self->SUPER::dbh_new(1);
$dbh->do('PRAGMA journal_mode = TRUNCATE');
$dbh->do('PRAGMA cache_size = 80000');
create_tables($dbh);
diff --git a/t/over.t b/t/over.t
index 4e630bcd..daa7176f 100644
--- a/t/over.t
+++ b/t/over.t
@@ -18,10 +18,15 @@ is($y, $x+1, 'tid increases');
$x = $over->sid('hello-world');
is(int($x), $x, 'integer sid');
$y = $over->sid('hello-WORLD');
-is($y, $x+1, 'sid ncreases');
+is($y, $x+1, 'sid increases');
is($over->sid('hello-world'), $x, 'idempotent');
+ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly');
$over->disconnect;
+$over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
+$over->connect;
+ok($over->{dbh}->{ReadOnly}, 'Over is ReadOnly');
+
$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
$over->connect;
is($over->sid('hello-world'), $x, 'idempotent across reopen');
^ permalink raw reply related [relevance 7%]
* [PATCH 0/5] a few more minor fixups
@ 2020-02-04 4:44 5% Eric Wong
2020-02-04 4:44 7% ` [PATCH 5/5] over: simplify read-only vs read-write checking Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-02-04 4:44 UTC (permalink / raw)
To: meta
Nothing earth shattering, serving $INBOX_URL/description
properly for v2 inboxes should make it easier to mirror
while preserving descriptions (only per-epoch descriptions
are propagated in manifest.js.gz).
Eric Wong (5):
www: stricter regexp for 405 errors
www: serve $INBOX_DIR/description as $INBOX_URL/description
inbox: simplify ->description and ->cloneurl
inbox: remove TODO item for msg_by_path
over: simplify read-only vs read-write checking
lib/PublicInbox/Inbox.pm | 26 ++++++++++----------------
lib/PublicInbox/Over.pm | 7 +++----
lib/PublicInbox/OverIdx.pm | 2 +-
lib/PublicInbox/WWW.pm | 13 ++++++++++++-
t/httpd.t | 5 +++++
t/over.t | 7 ++++++-
t/plack.t | 2 ++
t/psgi_v2.t | 3 +++
8 files changed, 42 insertions(+), 23 deletions(-)
^ permalink raw reply [relevance 5%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-02-04 4:44 5% [PATCH 0/5] a few more minor fixups Eric Wong
2020-02-04 4:44 7% ` [PATCH 5/5] over: simplify read-only vs read-write checking Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).