"test" producing unexpected results after "chmod"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

"test" producing unexpected results after "chmod"

Steven Penny
With Linux, these commands produce expected results:

    $ cd /tmp
    $ touch alpha.txt
    $ test -r alpha.txt; echo "$?"
    0
    $ chmod -r alpha.txt
    $ test -r alpha.txt; echo "$?"
    1
    $ chmod +r alpha.txt
    $ test -r alpha.txt; echo "$?"
    0

However with Cygwin, unexpected results are produced:

    $ cd /tmp
    $ touch alpha.txt
    $ test -r alpha.txt; echo "$?"
    0
    $ chmod -r alpha.txt
    $ test -r alpha.txt; echo "$?"
    0

It seems Cygwin is not able to produce non-readable files.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: "test" producing unexpected results after "chmod"

marco atzeri-4
Am 23.12.2018 um 06:59 schrieb Steven Penny:

> With Linux, these commands produce expected results:
>
>     $ cd /tmp
>     $ touch alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0
>     $ chmod -r alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     1
>     $ chmod +r alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0
>
> However with Cygwin, unexpected results are produced:
>
>     $ cd /tmp
>     $ touch alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0
>     $ chmod -r alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0
>
> It seems Cygwin is not able to produce non-readable files.
>

you are missing the point that the Windows filesystem
has additional ACL permission as indicated by the "+"
in the ls output.
If you remove those permissions the test case replicate
Linux results.


$ mkdir pippo

$ ls -l | grep pippo
drwx------+ 1 Marco Kein    0 Dec 23 07:03 pippo
           ^ ACL additional permissions


$ getfacl pippo/
# file: pippo/
# owner: Marco
# group: Kein
user::rwx
group::---
other::---
default:user::rwx
default:group::r-x
default:other::r-x

$ setfacl -k pippo

$ ls -l |grep pippo
drwx------  1 Marco Kein    0 Dec 23 07:05 pippo

$ getfacl pippo/
# file: pippo/
# owner: Marco
# group: Kein
user::rwx
group::---
other::---


$ cd pippo
$ touch alpha.txt
$ test -r alpha.txt; echo "$?"
0

$ chmod -r alpha.txt
$ test -r alpha.txt; echo "$?"
1

$ chmod +r alpha.txt
$ test -r alpha.txt; echo "$?"
0

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: "test" producing unexpected results after "chmod"

Andrey Repin
In reply to this post by Steven Penny
Greetings, Steven Penny!

> With Linux, these commands produce expected results:

>     $ cd /tmp
>     $ touch alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0
>     $ chmod -r alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     1
>     $ chmod +r alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0

> However with Cygwin, unexpected results are produced:

>     $ cd /tmp
>     $ touch alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0
>     $ chmod -r alpha.txt
>     $ test -r alpha.txt; echo "$?"
>     0

> It seems Cygwin is not able to produce non-readable files.

It's not Cygwin, it's test, like many other programs in this case, make false
assumptions on file readability/writability based on their interpretation of
file permissions.

The only true test for readability is to open file for reading.
The only true test for writability is to open file for writing.
Successfully.

The rest is merely a guesswork.


--
With best regards,
Andrey Repin
Monday, December 24, 2018 1:17:48

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple