user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 5/5] over: simplify read-only vs read-write checking
Date: Tue,  4 Feb 2020 04:44:25 +0000
Message-ID: <20200204044425.14031-6-e@yhbt.net> (raw)
In-Reply-To: <20200204044425.14031-1-e@yhbt.net>

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');

      parent reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-04  4:44 [PATCH 0/5] a few more minor fixups Eric Wong
2020-02-04  4:44 ` [PATCH 1/5] www: stricter regexp for 405 errors Eric Wong
2020-02-04  4:44 ` [PATCH 2/5] www: serve $INBOX_DIR/description as $INBOX_URL/description Eric Wong
2020-02-04  4:44 ` [PATCH 3/5] inbox: simplify ->description and ->cloneurl Eric Wong
2020-02-04  4:44 ` [PATCH 4/5] inbox: remove TODO item for msg_by_path Eric Wong
2020-02-04  4:44 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200204044425.14031-6-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git