2 # Copyright (C) 2020-2021 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::NDC_PP';
10 skip 'test is Linux-only', $nr if $^O ne 'linux';
11 my $dir = $ENV{BTRFS_TESTDIR};
12 skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
13 require_cmd('chattr', 1) or skip 'chattr(1) not installed', $nr;
14 my $lsattr = require_cmd('lsattr', 1) or
15 skip 'lsattr(1) not installed', $nr;
16 my $tmp = File::Temp->newdir('nodatacow-XXXX', DIR => $dir);
17 my $dn = $tmp->dirname;
19 my $name = "$dn/pp.f";
20 open my $fh, '>', $name or BAIL_OUT "open($name): $!";
21 my $pp_sub = \&PublicInbox::NDC_PP::nodatacow_fd;
22 $pp_sub->(fileno($fh));
23 my $res = xqx([$lsattr, $name]);
24 like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with pure Perl");
27 mkdir($name) or BAIL_OUT "mkdir($name) $!";
28 PublicInbox::NDC_PP::nodatacow_dir($name);
29 $res = xqx([$lsattr, '-d', $name]);
30 like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl");
33 my $ic_sub = \&PublicInbox::Spawn::nodatacow_fd;
34 $pp_sub == $ic_sub and
35 skip 'Inline::C or Linux kernel headers missing', 2;
36 open $fh, '>', $name or BAIL_OUT "open($name): $!";
37 $ic_sub->(fileno($fh));
38 $res = xqx([$lsattr, $name]);
39 like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with Inline::C");
42 mkdir($name) or BAIL_OUT "mkdir($name) $!";
43 PublicInbox::Spawn::nodatacow_dir($name);
44 $res = xqx([$lsattr, '-d', $name]);
45 like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with Inline::C");