Commit Diff


commit - 75983083f49930cbff74c2bdbbce265dc5302009
commit + 70b47196e34f4f26bce03cb299d75aee2b6e34f6
blob - 64c2c1d2c23d1ef79864fae470b8f0ac56c78ffe
blob + c6d98d05be00e5d6a19e725c37a14e6f92b304df
--- Makefile
+++ Makefile
@@ -1,10 +1,11 @@
 MDIR =		${HOME}/Mail/gameoftrees
 OUTDIR =	/var/www/marc
+CSUMDIR =	${HOME}/.cache/gotmarc/threadsum
 
 .PHONY: all assets images dirs gzip clean scaleimgs
 
 all: assets
-	@env MDIR="${MDIR}" OUTDIR="${OUTDIR}" ./gotmarc
+	@env MDIR="${MDIR}" OUTDIR="${OUTDIR}" CSUMDIR="${CSUMDIR}" ./gotmarc
 
 assets: dirs images ${OUTDIR}/style.css
 
@@ -23,6 +24,7 @@ ${OUTDIR}/style.css: style.css
 	cp $? $@
 
 dirs:
+	@mkdir -p ${CSUMDIR}
 	@mkdir -p ${OUTDIR}/mail/
 	@mkdir -p ${OUTDIR}/parts/
 	@mkdir -p ${OUTDIR}/text/
blob - 2d71787d92cced740dd2d576f6827838c7594e18
blob + 156d1af40f321e8496e0f17d0f101e9bd5c19bd3
--- gotmarc
+++ gotmarc
@@ -7,6 +7,7 @@ export MBLAZE_PAGER=cat
 export OUTDIR="${OUTDIR:-/var/www/marc}"
 
 : ${MDIR:?not defined}
+: ${CSUMDIR:?not defined}
 
 fmt='%i-%R %16D<%64f>%128S'
 mlist "${MDIR}" | mthread -r | mscan -f "$fmt" | ./pe | ./mkindex
blob - fb58b75049afccb735eaa8a43ed57846bb7f76d0
blob + 56d7c607a3cfd9f8e92396ffd70c7bce43d193af
--- mexp
+++ mexp
@@ -68,7 +68,6 @@ while (<>) {
 	die "unknown tid" unless defined $tid;
 
 	my $dest = "$outdir/mail/$mid.html";
-	next if -f $dest;
 
 	open(my $fh, '>', "$dest") or die "can't open $dest: $!";
 
blob - 871384da610e9b004ff4aa6e19419da2465492db
blob + a32837235a1e361e572ac8cb931e8b188a902a02
--- pe
+++ pe
@@ -8,27 +8,77 @@ use open ":std", ":encoding(UTF-8)";
 use strict;
 use warnings;
 use v5.32;
+
+use Digest::SHA;
+use Encode qw(encode);
 use IO::Poll qw(POLLOUT);
 
 use OpenBSD::Pledge;
 use OpenBSD::Unveil;
 
+use lib ".";
+use GotMArc qw(parse);
+
 my $jobs = $ENV{'MAKE_JOBS'} // 1;
 
+my $csumdir = $ENV{'CSUMDIR'};
+die '$CSUMDIR undefined' unless defined $csumdir;
+
 my $poll = IO::Poll->new();
 for (1..$jobs) {
 	open(my $kid, '|-', './mexp') or die "can't exec ./mexp: $!";
 	$poll->mask($kid => POLLOUT);
 }
 
+# get current thread checksum
+sub thrsum {
+	my $sha = Digest::SHA->new(256);
+	$sha->add(encode('UTF-8', $_)) for @_;
+	return $sha->hexdigest;
+}
+
+# get stored thread checksum
+sub oldsum {
+	my $tid = shift;
+	open my $fh, '<', "$csumdir/$tid" or return "";
+	my $sum = <$fh>;
+	chomp $sum;
+	return $sum;
+}
+
+# save thread checksum
+sub savesum {
+	my ($tid, $sum) = @_;
+	open my $fh, '>', "$csumdir/$tid"
+	    or die "can't open checksum file $csumdir/$tid: $!";
+	say $fh $sum;
+	close $fh;
+}
+
 sub process {
+	my @entries = @_;
+
+	return unless @entries;
+
+	local $_ = $entries[0];
+	my ($level, $fname, $mid, $date, $from, $subj) = parse;
+	die "wtf?" if $level != 0;
+
+	my $tid = $mid;
+	my $thrsum = thrsum @_;
+	my $oldsum = oldsum $tid;
+	return if $thrsum eq $oldsum;
+
 	die "poll: $!" if $poll->poll() == -1;
 	my @handles = $poll->handles(POLLOUT) or die "no procs ready?";
 	my $handle = $handles[int(rand(@handles))];
-	print $handle $_ foreach @_;
+	print $handle $_ foreach @entries;
+
+	savesum($tid, $thrsum);
 }
 
-pledge("stdio") or die "pledge: $!";
+unveil($csumdir, "rwc") or die "unveil $csumdir: $!";
+pledge("stdio rpath wpath cpath") or die "pledge: $!";
 
 my @thread;
 while (<>) {