user/dev discussion of public-inbox itself
 help / color / Atom feed
8c0cc18425b4c65aff680dbbd51e05b3bf90aa3a blob 2231 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Emergency Maildir delivery for MDA
package PublicInbox::Emergency;
use strict;
use warnings;
use Fcntl qw(:DEFAULT SEEK_SET);
use Sys::Hostname qw(hostname);
use IO::Handle; # ->flush, ->autoflush

sub new {
	my ($class, $dir) = @_;

	-d $dir or mkdir($dir) or die "failed to mkdir($dir): $!\n";
	foreach (qw(new tmp cur)) {
		my $d = "$dir/$_";
		next if -d $d;
		-d $d or mkdir($d) or die "failed to mkdir($d): $!\n";
	}
	bless { dir => $dir, files => {}, t => 0, cnt => 0, pid => $$ }, $class;
}

sub _fn_in {
	my ($self, $dir) = @_;
	my @host = split(/\./, hostname);
	my $now = time;
	if ($self->{t} != $now) {
		$self->{t} = $now;
		$self->{cnt} = 0;
	} else {
		$self->{cnt}++;
	}

	my $f;
	do {
		$f = "$self->{dir}/$dir/$self->{t}.$$"."_$self->{cnt}.$host[0]";
		$self->{cnt}++;
	} while (-e $f);
	$f;
}

sub prepare {
	my ($self, $strref) = @_;

	die "already in transaction: $self->{tmp}" if $self->{tmp};
	my ($tmp, $fh);
	do {
		$tmp = _fn_in($self, 'tmp');
		$! = undef;
	} while (!sysopen($fh, $tmp, O_CREAT|O_EXCL|O_RDWR) && $!{EEXIST});
	print $fh $$strref or die "write failed: $!";
	$fh->flush or die "flush failed: $!";
	$fh->autoflush(1);
	$self->{fh} = $fh;
	$self->{tmp} = $tmp;
}

sub abort {
	my ($self) = @_;
	delete $self->{fh};
	my $tmp = delete $self->{tmp} or return;

	unlink($tmp) or warn "Failed to unlink $tmp: $!";
	undef;
}

sub fh {
	my ($self) = @_;
	my $fh = $self->{fh} or die "{fh} not open!\n";
	seek($fh, 0, SEEK_SET) or die "seek(fh) failed: $!";
	sysseek($fh, 0, SEEK_SET) or die "sysseek(fh) failed: $!";
	$fh;
}

sub commit {
	my ($self) = @_;
	$$ == $self->{pid} or return; # no-op in forked child

	delete $self->{fh};
	my $tmp = delete $self->{tmp} or return;
	my $new;
	do {
		$new = _fn_in($self, 'new');
	} while (!link($tmp, $new) && $!{EEXIST});
	my @sn = stat($new) or die "stat $new failed: $!";
	my @st = stat($tmp) or die "stat $tmp failed: $!";
	if ($st[0] == $sn[0] && $st[1] == $sn[1]) {
		unlink($tmp) or warn "Failed to unlink $tmp: $!";
	} else {
		warn "stat($new) and stat($tmp) differ";
	}
}

sub DESTROY { commit($_[0]) }

1;
debug log:

solving 8c0cc184 ...
found 8c0cc184 in https://80x24.org/public-inbox.git

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