diff mbox series

[v2,1/2] common/rc: Check 'tPnE' flags on a directory instead of a regilar file

Message ID 20200914051400.32057-1-yangx.jy@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show
Series [v2,1/2] common/rc: Check 'tPnE' flags on a directory instead of a regilar file | expand

Commit Message

Xiao Yang Sept. 14, 2020, 5:13 a.m. UTC
'tPnE' flags are only valid for a directory so check them on a directory.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 common/rc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Sept. 14, 2020, 7:26 a.m. UTC | #1
On Mon, Sep 14, 2020 at 01:13:59PM +0800, Xiao Yang wrote:
> 'tPnE' flags are only valid for a directory so check them on a directory.
> 
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>

The change looks good, but I wonder if we should split the chattr
tests into

_require_chattr_file_flag

and

_require_chattr_dir_flag

to make the whole thing a little less convoluted..
Xiao Yang Sept. 17, 2020, 4:05 a.m. UTC | #2
On 2020/9/14 15:26, Christoph Hellwig wrote:
> On Mon, Sep 14, 2020 at 01:13:59PM +0800, Xiao Yang wrote:
>> 'tPnE' flags are only valid for a directory so check them on a directory.
>>
>> Signed-off-by: Xiao Yang<yangx.jy@cn.fujitsu.com>
> The change looks good, but I wonder if we should split the chattr
> tests into
>
> _require_chattr_file_flag
>
> and
>
> _require_chattr_dir_flag
>
> to make the whole thing a little less convoluted..
Hi Christoph,

Sorry for the late reply.

It seems hard to factor out _require_chattr_file_flag() and 
_require_chattr_dir_flag()
because we need to get attribute after running chattr command and then check
attribute after parsing all stderr of chattr command.
Could you provide me some detailed guide? Thanks a lot :-)

Best Regards,
Xiao Yang
>
>
> .
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index aa5a7409..6487b9f2 100644
--- a/common/rc
+++ b/common/rc
@@ -2163,14 +2163,23 @@  _require_xfs_io_command()
 	local testio
 	case $command in
 	"chattr")
+		local testdir=$TEST_DIR/$$.attr_dir
+		mkdir $TEST_DIR/$$.attr_dir
 		if [ -z "$param" ]; then
 			param=s
 		fi
 		# Test xfs_io chattr support AND
 		# filesystem FS_IOC_FSSETXATTR support
-		testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
-		$XFS_IO_PROG -F -f -r -c "chattr -$param" $testfile 2>&1
+		# 'tPnE' flags are only valid for a directory so check them on a directory.
+		if echo "$param" | egrep -q 't|P|n|E'; then
+			testio=`$XFS_IO_PROG -F -c "chattr +$param" $testdir 2>&1`
+			$XFS_IO_PROG -F -r -c "chattr -$param" $testdir 2>&1
+		else
+			testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
+			$XFS_IO_PROG -F -r -c "chattr -$param" $testfile 2>&1
+		fi
 		param_checked="+$param"
+		rm -rf $testdir 2>&1 > /dev/null
 		;;
 	"chproj")
 		testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`