summaryrefslogtreecommitdiff
path: root/perl5
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-07-12 13:14:25 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-07-12 13:41:50 -0700
commitecac9d421edf40894788d04d9f33be2b625e45f4 (patch)
tree73d3ddc402a0afb41e16b5bb7b519205558f5754 /perl5
parent6f51a6b4f4051f7728465d96c5328218f39d27f9 (diff)
downloaddotfiles-ecac9d421edf40894788d04d9f33be2b625e45f4.tar.gz
store Gnus/notmuch's copy of annexed mail in a single maildir's cur/
Diffstat (limited to 'perl5')
-rw-r--r--perl5/Local/Homedir/Mail.pm48
1 files changed, 24 insertions, 24 deletions
diff --git a/perl5/Local/Homedir/Mail.pm b/perl5/Local/Homedir/Mail.pm
index f34a21e9..6ee94046 100644
--- a/perl5/Local/Homedir/Mail.pm
+++ b/perl5/Local/Homedir/Mail.pm
@@ -20,7 +20,7 @@ use strict;
use warnings;
use constant THIRTYONE => 31 * 24 * 60 * 60;
-use File::Spec::Functions qw(catfile);
+use File::Spec::Functions qw(catfile splitpath);
use File::Temp qw(tempdir);
use File::Path qw(remove_tree);
use IO::Compress::Gzip qw(gzip $GzipError);
@@ -73,28 +73,26 @@ sub archive_to_mbox {
$mgr->moveMessage($mbox, $message);
}
+ $expanded->acceptMessages;
$mgr->closeAllFolders;
+ open my $touch_fh, ">",
+ catfile($expanded_path, "." . (splitpath $mbox_path)[2]) . ".done";
gzip($mbox_path, "$mbox_path.gz")
or die "gzip failed: $GzipError\n";
unlink $mbox_path if -e "$mbox_path.gz";
- make_maildir_readonly($expanded_path);
}
sub expand_mbox {
- my ($source_path, $expanded_path) = @_;
- my $lockfile = $expanded_path . ".lock";
-
- # check whether we got halfway there, or we finished it
- if (-e $lockfile) {
- remove_tree($expanded_path);
- unlink $lockfile;
- } elsif (-e $expanded_path) {
- return;
- }
+ my ($source_path, $target) = @_;
+ (my $source_name = (splitpath $source_path)[2]) =~ s/\.gz$//;
+ my $expanded_path = catfile $target, ".$source_name";
+ my $donefile = $expanded_path . ".done";
+
+ # Check whether we finished, or got partway there.
+ return if -e $donefile;
+ remove_tree($expanded_path) if -e $expanded_path;
- # lock this one
- open my $touch_fh, '>', $lockfile;
- close $touch_fh;
+ -e or mkdir for $target, map catfile($target, $_), "cur", "new", "tmp";
# unzip it to (what is hopefully a) tmpfs, since Mail::Box can
# only accept a path to an unzipped mbox
@@ -123,21 +121,23 @@ sub expand_mbox {
$mgr->copyMessage($expanded, $message);
}
$source->close(write => "NEVER");
+ $expanded->acceptMessages;
$expanded->close;
- make_maildir_readonly($expanded_path);
- # mark as done
- unlink $lockfile;
+ # Now we move all the files the old fashioned way, so that it's fast.
+ # It's safe because the filenames begin with a timestamp, so there really
+ # oughtn't be any collisions, and in any case this whole thing is a cache.
+ opendir my $dirh, catfile $expanded_path, "cur";
+ while (readdir $dirh) {
+ my $s = catfile $expanded_path, "cur", $_;
+ -f $s and rename $s, catfile $target, "cur", $_;
+ }
+ open my $touch_fh, ">", $donefile;
# nuke the tempdir now to avoid running out of ramdisk if we're
# expanding a lot of mboxes
remove_tree($dir);
-}
-
-sub make_maildir_readonly {
- chmod 0500, catfile($_[0], "cur"), catfile($_[0], "new"),
- catfile($_[0], "tmp");
- chmod 0400, glob "$_[0]/cur/* $_[0]/new/* $_[0]/tmp/*";
+ remove_tree($expanded_path);
}
1;