2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
6 use_ok 'PublicInbox::Syscall';
8 # btrfs on Linux is copy-on-write (COW) by default. As of Linux 5.7,
9 # this still leads to fragmentation for SQLite and Xapian files where
10 # random I/O happens, so we disable COW just for SQLite files and Xapian
11 # directories. Disabling COW disables checksumming, so we only do this
12 # for regeneratable files, and not canonical git storage (git doesn't
13 # checksum refs, only data under $GIT_DIR/objects).
17 skip 'test is Linux-only', $nr if $^O ne 'linux';
18 my $dir = $ENV{BTRFS_TESTDIR};
19 skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
21 my $lsattr = require_cmd('lsattr', 1) or
22 skip 'lsattr(1) not installed', $nr;
24 my $tmp = File::Temp->newdir('nodatacow-XXXX', DIR => $dir);
25 my $dn = $tmp->dirname;
27 my $name = "$dn/pp.f";
28 open my $fh, '>', $name or BAIL_OUT "open($name): $!";
29 PublicInbox::Syscall::nodatacow_fh($fh);
30 my $res = xqx([$lsattr, $name]);
32 BAIL_OUT "lsattr(1) fails in $dir" if $?;
33 like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with pure Perl");
36 mkdir($name) or BAIL_OUT "mkdir($name) $!";
37 PublicInbox::Syscall::nodatacow_dir($name);
38 $res = xqx([$lsattr, '-d', $name]);
39 like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl");