user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH] v2writable: use {inboxdir} for msgmap->tmp_clone
@ 2020-07-28 23:25 Eric Wong
  2020-07-29 11:32 ` Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2020-07-28 23:25 UTC (permalink / raw)
  To: meta

Otherwise, a user is more likely to remove the msgmap-XXXXXXXX
SQLite file from $TMPDIR and cause SQLite to error out.
---
 lib/PublicInbox/Msgmap.pm     | 4 ++--
 lib/PublicInbox/V2Writable.pm | 2 +-
 t/msgmap.t                    | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 839ddf7c..51b6a68c 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -48,8 +48,8 @@ sub new_file {
 
 # used to keep track of used numeric mappings for v2 reindex
 sub tmp_clone {
-	my ($self) = @_;
-	my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, TMPDIR => 1);
+	my ($self, $dir) = @_;
+	my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, DIR => $dir);
 	my $tmp;
 	if ($self->{dbh}->can('sqlite_backup_to_dbh')) {
 		$tmp = ref($self)->new_file($fn, 2);
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 6908bd2e..6b0bdc73 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -1225,7 +1225,7 @@ sub index_sync {
 		# only for batch performance.
 		$self->{mm}->{dbh}->rollback;
 		$self->{mm}->{dbh}->begin_work;
-		$sync->{mm_tmp} = $self->{mm}->tmp_clone;
+		$sync->{mm_tmp} = $self->{mm}->tmp_clone($self->{inboxdir});
 	}
 	if ($sync->{index_max_size} = $self->{ibx}->{index_max_size}) {
 		$sync->{index_oid} = \&index_oid;
diff --git a/t/msgmap.t b/t/msgmap.t
index 1d7d1e87..437e106e 100644
--- a/t/msgmap.t
+++ b/t/msgmap.t
@@ -60,7 +60,7 @@ my $orig = $d->mid_insert('spam@1');
 $d->mid_delete('spam@1');
 is($d->mid_insert('spam@2'), 1 + $orig, "last number not recycled");
 
-my $tmp = $d->tmp_clone;
+my $tmp = $d->tmp_clone($tmpdir);
 is_deeply([$d->minmax], [$tmp->minmax], 'Cloned temporary DB matches');
 ok($tmp->mid_delete('spam@2'), 'temporary DB is writable');
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] v2writable: use {inboxdir} for msgmap->tmp_clone
  2020-07-28 23:25 [PATCH] v2writable: use {inboxdir} for msgmap->tmp_clone Eric Wong
@ 2020-07-29 11:32 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2020-07-29 11:32 UTC (permalink / raw)
  To: meta

Eric Wong <e@yhbt.net> wrote:
> +	my ($self, $dir) = @_;
> +	my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, DIR => $dir);
>  	my $tmp;
>  	if ($self->{dbh}->can('sqlite_backup_to_dbh')) {
>  		$tmp = ref($self)->new_file($fn, 2);
> diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
> index 6908bd2e..6b0bdc73 100644
> --- a/lib/PublicInbox/V2Writable.pm
> +++ b/lib/PublicInbox/V2Writable.pm
> @@ -1225,7 +1225,7 @@ sub index_sync {
>  		# only for batch performance.
>  		$self->{mm}->{dbh}->rollback;
>  		$self->{mm}->{dbh}->begin_work;
> -		$sync->{mm_tmp} = $self->{mm}->tmp_clone;
> +		$sync->{mm_tmp} = $self->{mm}->tmp_clone($self->{inboxdir});

That is wrong, and the `undef' didn't get noticed since
tempfile() sees `DIR => undef' and just uses the current
working directory.  Will squash this in:

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 6b0bdc73..e071bc1e 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -1225,7 +1225,8 @@ sub index_sync {
 		# only for batch performance.
 		$self->{mm}->{dbh}->rollback;
 		$self->{mm}->{dbh}->begin_work;
-		$sync->{mm_tmp} = $self->{mm}->tmp_clone($self->{inboxdir});
+		$sync->{mm_tmp} =
+			$self->{mm}->tmp_clone($self->{ibx}->{inboxdir});
 	}
 	if ($sync->{index_max_size} = $self->{ibx}->{index_max_size}) {
 		$sync->{index_oid} = \&index_oid;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-29 11:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 23:25 [PATCH] v2writable: use {inboxdir} for msgmap->tmp_clone Eric Wong
2020-07-29 11:32 ` Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	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

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index 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/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

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