Subject: Re: [msysGit] Re: [PATCH] t/lib-httpd: switch SANITY check for NOT_ROOT

From: Torsten Bögershausen <[email-masked]>
Date: Fri, 23 Jan 2015 22:24:17 +0100

On 2015-01-22 23.07, Junio C Hamano wrote:
> Torsten Bögershausen <[email-masked]> writes:
> 
>> If I run that sequence manually:
>> chmod 755 .
>> touch x
>> chmod a-w .
>> rm x
>> touch y
>>
>> x is gone, (but shoudn't according to POSIX)
>> y is not created, "access denied"
> 
> Good (or is that Sad?).
> 
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -1039,7 +1039,17 @@ test_lazy_prereq NOT_ROOT '
>>  # When the tests are run as root, permission tests will report that
>>  # things are writable when they shouldn't be.
>>  test_lazy_prereq SANITY '
>> -       test_have_prereq POSIXPERM,NOT_ROOT
>> +       mkdir ds &&
>> +       touch ds/x &&
>> +       chmod -w ds &&
>> +       if rm ds/x
>> +       then
>> +               chmod +w ds
>> +               false
>> +       else
>> +               chmod +w ds
>> +               true
>> +       fi
>>  '
> 
> It looks like a better approach overall.
> 
> Because we cannot know where $(pwd) is when lazy prereq is evaluated
> (it typically is at the root of the trash hierarchy, but not always)
> and we would not want to add, leave or remove random files in the
> working tree that are not expected by the tests proper (e.g. a test
> that counts untracked paths are not expecting ds/ to be there), your
> actual "fix" may need to be a bit more careful, though.
> 
> Thanks.
> 

Hm,
I think there are 2 different possiblities to go further,
either to always switch off SANITY for CYGWIN (or Windows in general).
I haven't tested anything, the idea came up while writing this email.

The other way is to go away from the hard coded "we know we are root,
so SANITY must be false, or we know that Windows is not 100% POSIX",
and probe the OS/FS dynamically.

The following probably deserves the price for the most clumsy prerequisite
ever written.
(Copy&Paste of a real patch into the mailer, not sure if it applies)

It has been tested under Mac OS, root@Mac OS, Cygwin / Msysgit
What do you think ?

-- >8 --
Subject: [PATCH 1/2] test-lib.sh: Improve SANITY

SANITY was not set when running as root,
but this is not 100% reliable for CYGWIN:

A file is allowed to be deleted when the containing
directory does not have write permissions.

Signed-off-by: Torsten Bögershausen <[email-masked]>
---
 t/test-lib.sh | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 93f7cad..b8f736f 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1038,8 +1038,26 @@ test_lazy_prereq NOT_ROOT '
 
 # When the tests are run as root, permission tests will report that
 # things are writable when they shouldn't be.
+# Special check for CYGWIN (or Windows in general):
+# A file can be deleted, even if the containing directory does'nt
+# have write permissions
 test_lazy_prereq SANITY '
-	test_have_prereq POSIXPERM,NOT_ROOT
+	dsdir=$$ds
+	mkdir $dsdir &&
+	touch $dsdir/x &&
+	chmod -w $dsdir &&
+	if rm $dsdir/x
+	then
+		chmod +w $dsdir
+		rm -rf $dsdir
+		echo >&2 SANITY=false
+		false
+	else
+		chmod +w $dsdir
+		rm -rf $dsdir
+		echo >&2 SANITY=true
+		true
+	fi
 '
 
 GIT_UNZIP=${GIT_UNZIP:-unzip}
-- 

Subject: [PATCH 2/2] t2026 needs SANITY

When running as root 'prune directories with unreadable gitdir' in t2026 fails.
Protect this TC with SANITY

Signed-off-by: Torsten Bögershausen <[email-masked]>
---
 t/t2026-prune-linked-checkouts.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t2026-prune-linked-checkouts.sh b/t/t2026-prune-linked-checkouts.sh
index 170aefe..2936d52 100755
--- a/t/t2026-prune-linked-checkouts.sh
+++ b/t/t2026-prune-linked-checkouts.sh
@@ -33,7 +33,7 @@ EOF
 	! test -d .git/worktrees
 '
 
-test_expect_success POSIXPERM 'prune directories with unreadable gitdir' '
+test_expect_success SANITY 'prune directories with unreadable gitdir' '
 	mkdir -p .git/worktrees/def/abc &&
 	: >.git/worktrees/def/def &&
 	: >.git/worktrees/def/gitdir &&