2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::TestCommon;
8 use PublicInbox::Spawn qw(which);
9 use_ok 'PublicInbox::NDC_PP';
13 skip 'test is Linux-only', $nr if $^O ne 'linux';
14 my $dir = $ENV{BTRFS_TESTDIR};
15 skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
16 skip 'chattr(1) not installed', $nr unless which('chattr');
17 my $lsattr = which('lsattr') or skip 'lsattr(1) not installed', $nr;
18 my $tmp = File::Temp->newdir('nodatacow-XXXXX', DIR => $dir);
19 my $dn = $tmp->dirname;
21 my $name = "$dn/pp.f";
22 open my $fh, '>', $name or BAIL_OUT "open($name): $!";
23 my $pp_sub = \&PublicInbox::NDC_PP::nodatacow_fd;
24 $pp_sub->(fileno($fh));
25 my $res = xqx([$lsattr, $name]);
26 like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with pure Perl");
29 mkdir($name) or BAIL_OUT "mkdir($name) $!";
30 PublicInbox::NDC_PP::nodatacow_dir($name);
31 $res = xqx([$lsattr, '-d', $name]);
32 like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl");
35 my $ic_sub = \&PublicInbox::Spawn::nodatacow_fd;
36 $pp_sub == $ic_sub and
37 skip 'Inline::C or Linux kernel headers missing', 2;
38 open $fh, '>', $name or BAIL_OUT "open($name): $!";
39 $ic_sub->(fileno($fh));
40 $res = xqx([$lsattr, $name]);
41 like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with Inline::C");
44 mkdir($name) or BAIL_OUT "mkdir($name) $!";
45 PublicInbox::Spawn::nodatacow_dir($name);
46 $res = xqx([$lsattr, '-d', $name]);
47 like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with Inline::C");