about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-22 07:08:20 -0200
committerEric Wong <e@80x24.org>2021-04-22 17:05:47 -0400
commit311a5d37ad275cd75b1e64d87827c4d13fe4bfab (patch)
tree659fe9e67a6b0de748c1e38ee6f77bb636c5d0e7
parent91ae332610370d2a5da2cfb0bd1dff09463e5438 (diff)
downloadpublic-inbox-311a5d37ad275cd75b1e64d87827c4d13fe4bfab.tar.gz
We'll support nodatacow as we do in other SQLite DBs
-rw-r--r--lib/PublicInbox/IMAPTracker.pm22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm
index 6d4fb227..bcf7af2e 100644
--- a/lib/PublicInbox/IMAPTracker.pm
+++ b/lib/PublicInbox/IMAPTracker.pm
@@ -62,21 +62,27 @@ VALUES (?, ?, ?)
 }
 
 sub new {
-        my ($class, $url) = @_;
+        my ($class, $url, $dbname) = @_;
 
-        # original name for compatibility with old setups:
-        my $dbname = PublicInbox::Config->config_dir() . "/imap.sqlite3";
+        unless (defined($dbname)) {
+                # original name for compatibility with old setups:
+                $dbname = PublicInbox::Config->config_dir() . '/imap.sqlite3';
 
-        # use the new XDG-compliant name for new setups:
-        if (!-f $dbname) {
-                $dbname = ($ENV{XDG_DATA_HOME} //
-                        (($ENV{HOME} // '/nonexistent').'/.local/share')) .
-                        '/public-inbox/imap.sqlite3';
+                # use the new XDG-compliant name for new setups:
+                if (!-f $dbname) {
+                        $dbname = ($ENV{XDG_DATA_HOME} //
+                                        (($ENV{HOME} // '/nonexistent').
+                                         '/.local/share')) .
+                                '/public-inbox/imap.sqlite3';
+                }
         }
         if (!-f $dbname) {
                 require File::Path;
                 require File::Basename;
+                require PublicInbox::Spawn;
                 File::Path::mkpath(File::Basename::dirname($dbname));
+                open my $fh, '+>>', $dbname or die "failed to open $dbname: $!";
+                PublicInbox::Spawn::nodatacow_fd(fileno($fh));
         }
         my $self = bless { lock_path => "$dbname.lock", url => $url }, $class;
         $self->lock_acquire;