msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.29k stars 485 forks source link

chmod is ignored by msys2 #2612

Open dgleba opened 3 years ago

dgleba commented 3 years ago

Describe the issue

chmod is ignored by msys2 proper. chmod og-r file.txt has no effect.

After reading several posts on the web and looking for a document to describe the way it should work, I am left with no clear answer.

This issue has little useful info. https://github.com/msys2/MSYS2-packages/issues/2016

How should it work? Did I miss the document that describes how it should work?

Steps to Reproduce the Problem

Borrowed from another post.
touch foo
ls -lrt foo
-rw-r--r-- 1 utente NESSUNO 0 16 giu 18.59 foo

chmod go-r foo
ls -lrt foo
-rw-r--r-- 1 utente NESSUNO 0 16 giu 18.59 foo
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.18363 N/A Build 18363
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          admin
Original Install Date:     1/28/2020, 5:02:42 PM
System Boot Time:          8/22/2021, 7:56:29 AM
System Manufacturer:       Dell Inc.
System Model:              XPS 15 7590
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz
BIOS Version:              Dell Inc. 1.8.1, 7/3/2020
Biswa96 commented 1 year ago

chmod is not supposed to work in msys2. To change file permission, use icacls or takeown like commands which are specific to Microsoft Windows OS.

totszwai commented 1 year ago

Hum.... Then perhaps chmod shouldn't exists within MSYS2 space? I came here just as I discovered I couldn't apply executable to a shell script.

touch blah.sh
chmod 744 blah.sh

ls -rtl blah.sh
-rw-r--r-- 1 et5341 Corp+Group(2371)   87 Aug  3 11:49 blah.sh

Actually, something is weird with MSYS2 displaying the permission...

$ ls -rtl
total 6
-rwxr-xr-x 1 et5341 Corp+Group(2371) 1002 Jul  7 09:56 mock-installed.sh
-rw-r--r-- 1 et5341 Corp+Group(2371)   87 Aug  3 11:49 blah-from-msys2.sh
-rw-r--r-- 1 et5341 Corp+Group(2371)   87 Aug  3 11:58 blah-created-from-ubuntu22.sh

So the mock-installed.sh was a script that was created a while back, checked out from git, and some how it has the proper executable bit set correctly... however, the other 2 new files I tried to create, they don't. The one created from the Ubuntu 22.04 WSL2, it was chmod 755 and it still wouldn't show the executable bit under MSYS2... however if I ls the files in Ubuntu, everything shows up correctly with the executable bit set..?

Biswa96 commented 1 year ago

Add a shebang line in the shell script. It would automatically become executable.

totszwai commented 1 year ago

Ok, shebang'ed worked. Thanks. 😄

sskras commented 1 year ago

@totszwai, not to interfere with your original issue, but that works on both Cygwin:

image

... and on Midipix:

image

vadi2 commented 3 months ago

icacls doesn't seem to work either despite it saying it did. Here is an example in trying to make a file be readable only by the current user:

runneradmin@fv-az1434-66 MINGW64 ~
# icacls "$temp_key_file" /inheritance:r /remove:g "*S-1-1-0" /remove:g "*S-1-5-32-545"
processed file: C:/msys64/home/runneradmin/tmp.DYnm99oPwk 
Successfully processed 1 files; Failed processing 0 files

runneradmin@fv-az1434-66 MINGW64 ~
# stat -c "%a %n" "$temp_key_file"                                                                                                                                                                                                                                                 
644 /home/runneradmin/tmp.DYnm99oPwk

runneradmin@fv-az1434-66 MINGW64 ~
# icacls "$temp_key_file" /grant:r "$USERNAME:(R)"

processed file: C:/msys64/home/runneradmin/tmp.DYnm99oPwk 
Successfully processed 1 files; Failed processing 0 files

runneradmin@fv-az1434-66 MINGW64 ~
# stat -c "%a %n" "$temp_key_file"                                                                                                                                                                                                                                                 
644 /home/runneradmin/tmp.DYnm99oPwk
vadi2 commented 3 months ago

Running icacls within powershell.exe in a bash shell did the job.