about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-04-18 23:27:44 +0000
committerEric Wong <e@80x24.org>2018-04-18 23:40:52 +0000
commit2a353273079b2491cbceb20526d3c9dbf43d8f62 (patch)
treee84d1b4f39fbb63231c8b3585d14bcd1a7240136 /lib
parentcfb8d16578e7f2f2e300f9f436205e4a8fc7f322 (diff)
downloadpublic-inbox-2a353273079b2491cbceb20526d3c9dbf43d8f62.tar.gz
We can't have files with permissions inconsistent with what's
in git objects.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Msgmap.pm3
-rw-r--r--lib/PublicInbox/Over.pm6
-rw-r--r--lib/PublicInbox/V2Writable.pm16
3 files changed, 22 insertions, 3 deletions
diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index ec3d4f9d..6e758c1a 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -26,6 +26,9 @@ sub new {
 
 sub dbh_new {
         my ($f, $writable) = @_;
+        if ($writable && !-f $f) { # SQLite defaults mode to 0644, we want 0666
+                open my $fh, '+>>', $f or die "failed to open $f: $!";
+        }
         my $dbh = DBI->connect("dbi:SQLite:dbname=$f",'','', {
                 AutoCommit => 1,
                 RaiseError => 1,
diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm
index 07e54b64..30f2603f 100644
--- a/lib/PublicInbox/Over.pm
+++ b/lib/PublicInbox/Over.pm
@@ -15,7 +15,11 @@ use Compress::Zlib qw(uncompress);
 sub dbh_new {
         my ($self) = @_;
         my $ro = ref($self) eq 'PublicInbox::Over';
-        my $dbh = DBI->connect("dbi:SQLite:dbname=$self->{filename}",'','', {
+        my $f = $self->{filename};
+        if (!$ro && !-f $f) { # SQLite defaults mode to 0644, we want 0666
+                open my $fh, '+>>', $f or die "failed to open $f: $!";
+        }
+        my $dbh = DBI->connect("dbi:SQLite:dbname=$f",'','', {
                 AutoCommit => 1,
                 RaiseError => 1,
                 PrintError => 0,
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 1316d628..d8d75ec2 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -63,6 +63,7 @@ sub new {
         }
 
         $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
+        $v2ibx->umask_prepare;
 
         my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
         my $self = {
@@ -95,6 +96,13 @@ sub init_inbox {
 # mimics Import::add and wraps it for v2
 sub add {
         my ($self, $mime, $check_cb) = @_;
+        $self->{-inbox}->with_umask(sub {
+                _add($self, $mime, $check_cb)
+        });
+}
+
+sub _add {
+        my ($self, $mime, $check_cb) = @_;
 
         # spam check:
         if ($check_cb) {
@@ -348,12 +356,16 @@ sub remove_internal {
 
 sub remove {
         my ($self, $mime, $cmt_msg) = @_;
-        remove_internal($self, $mime, $cmt_msg);
+        $self->{-inbox}->with_umask(sub {
+                remove_internal($self, $mime, $cmt_msg);
+        });
 }
 
 sub purge {
         my ($self, $mime) = @_;
-        my $purges = remove_internal($self, $mime, undef, {});
+        my $purges = $self->{-inbox}->with_umask(sub {
+                remove_internal($self, $mime, undef, {});
+        });
         $self->idx_init if @$purges; # ->done is called on purges
         for my $i (0..$#$purges) {
                 defined(my $cmt = $purges->[$i]) or next;