# Go file permissions test by Brandon Dyck 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 (0–0777), sets those permissions on the file with `os.Chmod` and checks the resulting permissions with `os.Stat`. ## Usage ### `go-perm-test` Prints the results as a CSV in the format ```,``` where each set of permissions is an octal integer. ### `go-perm-test ` Inserts the results into an SQLite database called `filename`. There are two objects in the DB schema: a table `result_raw(expected INT, actual INT)` and a view `result`. The `result` view 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. ## Findings Permissions as observed through `os.Stat` depend entirely upon the owner's write bit set through `os.Chmod`: ``` sqlite> select distinct actual, expected_uw from result; actual|expected_uw 292|0 438|1 ``` This obviously isn't an exhaustive treatment of the subject, and I'm not really interested in doing one, but it corraborates [Michal Pristas’s findings.](https://archive.is/RZ8WP)