about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-08-08 04:59:48 +0000
committerEric Wong <e@yhbt.net>2020-08-08 10:47:11 +0000
commit683e5fbbfef867ff04b376b3d5230976004a6c7a (patch)
tree85b6cb3b3f40d88a51cf3b1d6902373f6318a836 /t
parent6e98887b3d539dd07c9d49e3334e48d720fc1e31 (diff)
downloadpublic-inbox-683e5fbbfef867ff04b376b3d5230976004a6c7a.tar.gz
support setting No_COW on Perl <5.22
fileno(DIRHANDLE) only works on Perl 5.22+, so we need to use
dirfd(3) ourselves from Inline::C (or rely on chattr(1) being
installed).

While we're at it, rename `set_nodatacow' to `nodatacow_fd'
for consistency with `nodatacow_dir'.
Diffstat (limited to 't')
-rw-r--r--t/nodatacow.t34
1 files changed, 25 insertions, 9 deletions
diff --git a/t/nodatacow.t b/t/nodatacow.t
index 87b6bdf7..e5b742a2 100644
--- a/t/nodatacow.t
+++ b/t/nodatacow.t
@@ -3,7 +3,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use Test::More;
-use File::Temp qw(tempfile);
+use File::Temp 0.19;
 use PublicInbox::TestCommon;
 use PublicInbox::Spawn qw(which);
 use_ok 'PublicInbox::NDC_PP';
@@ -15,20 +15,36 @@ SKIP: {
         skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
         skip 'chattr(1) not installed', $nr unless which('chattr');
         my $lsattr = which('lsattr') or skip 'lsattr(1) not installed', $nr;
-        my ($fh, $name) = tempfile(DIR => $dir, UNLINK => 1);
-        BAIL_OUT "tempfile: $!" unless $fh && defined($name);
-        my $pp_sub = \&PublicInbox::NDC_PP::set_nodatacow;
+        my $tmp = File::Temp->newdir('nodatacow-XXXXX', DIR => $dir);
+        my $dn = $tmp->dirname;
+
+        my $name = "$dn/pp.f";
+        open my $fh, '>', $name or BAIL_OUT "open($name): $!";
+        my $pp_sub = \&PublicInbox::NDC_PP::nodatacow_fd;
         $pp_sub->(fileno($fh));
         my $res = xqx([$lsattr, $name]);
-        like($res, qr/C/, "`C' attribute set with pure Perl");
+        like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with pure Perl");
+
+        $name = "$dn/pp.d";
+        mkdir($name) or BAIL_OUT "mkdir($name) $!";
+        PublicInbox::NDC_PP::nodatacow_dir($name);
+        $res = xqx([$lsattr, '-d', $name]);
+        like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl");
 
-        my $ic_sub = \&PublicInbox::Spawn::set_nodatacow;
+        $name = "$dn/ic.f";
+        my $ic_sub = \&PublicInbox::Spawn::nodatacow_fd;
         $pp_sub == $ic_sub and
-                skip 'Inline::C or Linux kernel headers missing', 1;
-        ($fh, $name) = tempfile(DIR => $dir, UNLINK => 1);
+                skip 'Inline::C or Linux kernel headers missing', 2;
+        open $fh, '>', $name or BAIL_OUT "open($name): $!";
         $ic_sub->(fileno($fh));
         $res = xqx([$lsattr, $name]);
-        like($res, qr/C/, "`C' attribute set with Inline::C");
+        like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with Inline::C");
+
+        $name = "$dn/ic.d";
+        mkdir($name) or BAIL_OUT "mkdir($name) $!";
+        PublicInbox::Spawn::nodatacow_dir($name);
+        $res = xqx([$lsattr, '-d', $name]);
+        like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with Inline::C");
 };
 
 done_testing;