We'll set nodatacow when detecting existing but empty
files, and also their directories in more cases (for
auxiliary -wal, -journal, -shm files). Hopefully
this keeps performance reasonable on CoW FSes.
sub dbh_new {
my ($self, $rw) = @_;
my $f = delete $self->{filename};
- if (!-f $f) { # SQLite defaults mode to 0644, we want 0666
+ if (!-s $f) { # SQLite defaults mode to 0644, we want 0666
if ($rw) {
require PublicInbox::Spawn;
+ my ($dir) = ($f =~ m!(.+)/[^/]+\z!);
+ PublicInbox::Spawn::nodatacow_dir($dir);
open my $fh, '+>>', $f or die "failed to open $f: $!";
PublicInbox::Spawn::nodatacow_fd(fileno($fh));
} else {
$base //= '';
my $f = $self->{filename} = "$dir/$base.sqlite3";
$self->{lock_path} = $opt->{lock_path} // "$dir/$base.flock";
- unless (-f $f) {
+ unless (-s $f) {
+ PublicInbox::Spawn::nodatacow_dir($dir); # for journal/shm/wal
open my $fh, '+>>', $f or die "failed to open $f: $!";
PublicInbox::Spawn::nodatacow_fd(fileno($fh));
}