[feature] Cannot test if file is immutable
Provide a way to test if a file is immutable (ideally via a file.stat(path) method. This allows scripts to check permissions before writing. Currently "permissions" is not effected by the immutable flag
➜ test golem list.eld
{"file_name": "file.txt", "size": 6, "owner": "lethicon", "group": "1000", "permissions": "100644", "modified": "2024-02-11 01:11:32 UTC", "type": "File"}
➜ test sudo chattr +i file.txt
➜ test golem list.eld
{"file_name": "file.txt", "size": 6, "owner": "lethicon", "group": "1000", "permissions": "100644", "modified": "2024-02-11 01:11:32 UTC", "type": "File"}
Instead of having the immutable flag show on file.stat(path), should it just be its own function (e.g. file.is_immutable(path))?
stat (or the stat() syscall) does not show the immutable flag, but lsattr does using ioctl()
I think it'll get complex if we do a function per file ACL (getfacl, selinux, windows cacls, immutable).
Instead let's add a base set of permission functions:
- file.get_perms(path) - Linux, macOS, BSD - return the octal perms.
- file.set_perms ^^ same
- file.get_extended_perms(path) - return a struct with each perm type:
{ "icacls": "C:\example.txt NT AUTHORITY\SYSTEM:(I)(F)\r\nBUILTIN\Administrators:(I)(F)\r\nWIN-PC\User:(I)(RX)\r\n\r\nSuccessfully processed 1 files; Failed processing 0 files", "attrs": "----i---------e---- example.txt", "secontext": "unconfined_u:object_r:user_home_t:s0", "facl": "# file: example.txt\n# owner: root\n# group: root\nuser::rw-\nuser:johndoe:r-x\ngroup::r--\nmask::r-x\nother::r--" }
Icacls - windows only. Attrs - lsattr output linux only. Secontext - SElinux file context string. Facl - get facl Linux only.
It'll be up to tome writers to check their OS and then parse extended file perms.
@deciphr you interested in tackling this?
@deciphr you interested in tackling this?
Sure