On 02/28/2012 10:31 PM, P. Martin wrote:
>> On Feb 28, 2012, Stefano Lattarini <stefano.lattar...@gmail.com> wrote: 
>>
>> Yes, that's why I should have asked for "chmod 000 a/b", not "chmod 000 a" 
>> :-(
> 
> I can do that too:
> 
> $ mkdir a a/b
> $ chmod 000 a/b
> $ find a -type d ! -perm -700
> a/b
> find: a/b: Permission denied
> $ echo exit status: $?
> exit status: 1
> $ find a -type d ! -perm -700 -exec chmod u+rwx '{}' \;
> $ echo exit status: $?
> exit status: 0
> $ ls -l a
> total 0
> drwx------  2 nibbles  staff  68 Feb 28 13:25 b
> 
> That is funky.
> 
Thanks for the confirmation.  The attached patch should fix this issue.
I will wait a couple of days before pushing, in case you want to give
it a try.

Thanks,
  Stefano
>From 90506026552e0d0e2dec91c72ea716dced1fefe5 Mon Sep 17 00:00:00 2001
Message-Id: <90506026552e0d0e2dec91c72ea716dced1fefe5.1330541781.git.stefano.lattar...@gmail.com>
From: Stefano Lattarini <stefano.lattar...@gmail.com>
Date: Sun, 26 Feb 2012 14:17:36 +0100
Subject: [PATCH] self checks: relax tests on cleanup

Some find(1) implementations have problems operating recursively on
directories having subdirectories with null permissions, even when
the permissions of such subdirectory should be fixed by find before
it descends into them; for example, with this setup:

  % mkdir a a/b
  % chmod 000 a/b

a command like this:

  % find a -type d ! -perm -700 -exec chmod u+rwx '{}' ';'

fails with this diagnostic on MacOS X 10.7:

  find: a/b: Permission denied

and with this diagnostic on Solaris 10:

  find: cannot read dir a/b: Permission denied

The problem is that our self checks were simply demanding too much
from our cleanup trap: our tests never use subdirectories with null
permissions, so it doesn't matter if the cleanup trap fails to
handle those.  Just relax the self checks to avoid such useless
testsuite noise.

* tests/self-check-cleanup.tap: Only try directories missing
write permissions, not with null permission.  That should be
enough for our usages.
---
 tests/self-check-cleanup.tap |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/tests/self-check-cleanup.tap b/tests/self-check-cleanup.tap
index 932bb42..bd59657 100755
--- a/tests/self-check-cleanup.tap
+++ b/tests/self-check-cleanup.tap
@@ -46,7 +46,11 @@ dir=dummy.dir
 do_clean ()
 {
   test -d $dir || return 0
-  find $dir -type d -exec chmod u+rwx '{}' ';' || :
+  # Don't try to be smart and use find here, that has caused issues
+  # and extra ERROR results in the past.  Be dumb and safe.
+  chmod u+rwx $dir || :
+  for d in $dir/*; do test ! -d $d || chmod u+rwx $d || :; done
+  for d in $dir/*/*; do test ! -d $d || chmod u+rwx $d || :; done
   rm -rf $dir
 }
 
@@ -62,17 +66,17 @@ fi
 cd ..
 chmod 000 $dir/sub/* $dir/file
 test $have_symlinks = yes && chmod 000 $dir/symlink
-chmod 000 $dir/sub $dir
-command_ok_ "pre-cleanup can deal with null-perms testdir" \
+chmod 500 $dir/sub $dir
+command_ok_ "pre-cleanup can deal with low-perms testdir" \
             $SHELL -c  '. ./defs' dummy.test
-command_ok_ "pre-cleanup removed null-perms testdir" \
+command_ok_ "pre-cleanup removed low-perms testdir" \
             eval 'test ! -f $dir && test ! -d $dir && test ! -r $dir'
 
 do_clean
 
 # Check that post-test cleanup works also with directories with
 # "null" permissions, and containing broken symlinks.
-command_ok_ "post-cleanup can deal with null-perms testdir" \
+command_ok_ "post-cleanup can deal with low-perms testdir" \
             $SHELL -c  '
   stderr_fileno_=2
   . ./defs || Exit 1
@@ -87,7 +91,7 @@ command_ok_ "post-cleanup can deal with null-perms testdir" \
   cd ..
   chmod 000 dir/sub/* dir/file
   test $have_symlinks = yes && chmod 000 dir/symlink
-  chmod 000 dir/sub dir
+  chmod 500 dir/sub dir
   :
 ' dummy.test
 command_ok_ "post-cleanup removed null-perms testdir" \
@@ -130,6 +134,7 @@ if test $have_symlinks = yes; then
   command_ok_ "post-cleanup chmod doesn't follow symlinks to dirs" \
               eval 'ls -ld dir | grep "^d---------.*dir"'
 
+  chmod u+rwx dir file
   rmdir dir
   rm -f file
 
-- 
1.7.9

Reply via email to