go-perm-test/README.md

30 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2024-08-19 22:30:30 +00:00
# Go file permissions test
by Brandon Dyck <brandon@dyck.us>
This is an experiment to see how `os.Chmod` and `os.Stat` interact on Windows. The program creates a temporary file, then for each possible set of permissions (00777), sets those permissions on the file with `os.Chmod` and checks the resulting permissions with `os.Stat`.
## Usage
2024-08-20 03:23:58 +00:00
```
go-perm-test <filename>
```
2024-08-19 22:30:30 +00:00
Inserts the results into an SQLite database called `filename`.
2024-08-20 03:23:58 +00:00
There are four objects in the DB schema: tables named `{file,dir}_result_raw(expected INT, actual INT)` and views named `{file,dir}_result`.
2024-08-19 22:30:30 +00:00
2024-08-20 03:23:58 +00:00
The `result` views breaks down the permissions into separate fields: The raw data are in the `expected` and `actual` columns, 3-bit fields are in `{expected,actual}_{u,g,o}` columns, and 1-bit fields are in `{expected,actual}_{u,g,o}{r,w,x}` columns.
2024-08-19 22:30:30 +00:00
## Findings
Permissions as observed through `os.Stat` depend entirely upon the owner's write bit set through `os.Chmod`:
```
2024-08-20 03:23:58 +00:00
sqlite> select distinct format('%o', actual), expected_uw from dir_result;
20000000555|0
20000000777|1
sqlite> select distinct format('%o', actual), expected_uw from file_result;
444|0
666|1
2024-08-19 22:30:30 +00:00
```
This obviously isn't an exhaustive treatment of the subject, and I'm not really interested in doing one, but it corraborates [Michal Pristass findings.](https://archive.is/RZ8WP)