i was quite surprised to discover that there is no api for changing the owner or group for a file/directory in std. I started playing issue hopscotch trying to see what the state of this is now, but thought that I would ask. IMHO, this should probably be considered bread and butter/ table stakes for a modern language with a full featured std lib. I mean it isn’t sexy like async but…
According to the docs:
This function currently corresponds to the
chmodfunction on Unix and the
SetFileAttributesfunction on Windows
But that is chmod not chown and chgrp
Yeah, sorry for the original answer, should have had my pu-erh first, instead of immediately reacting to a combination of factual error (there’s no chmod in stdlib) and a condescending tone of the question.
Indeed there’s only chmod, and no chown or chgroup. The latter two should probably be in the stdlib under
std::os::unix::fs, given that we already expose uid and gid via
MetadataExt. Looks like somebody needs to draft a short RFC and PR?
That said, this functionality is definitely not cross-platform, and only scratches the surface of access control, so needing to use an extern crate (nix or winapi) doesn’t seem like an end of the world to me personally.
Sorry for coming off condescending. That wasn’t really my intention.
It just struck me as odd that Rust, which has seen this amazing growth in all manner of apis at breakneck speed, and is, in my opinion, an absolute joy in general to program in, is sort of missing this pretty fundamental api from a systems programming perspective.
There was this ticket, “File owner/group API in new std::fs module #23892”, which got closed with the comment that it would end up in this rfc (“Expand the scope of std::fs #939”), but it seems like it didn’t There is a fairly recent (2year old) comment about chown being missing from Steve Klabnik, but the exchange didn’t seem to result in the RFC getting updated.
And yes, one can use a crate or two…
std is missing lots of pretty fundamental APIs – but that’s by design
There’s a lot more to permissions than just chown and chmod. Access control lists are an extremely complex topic, and each major platform has its own version of them.
std has shied away from providing this sort of API just because of how much design work is required to get a good API. The fact that there is no third party crate for cross platform access control lists just goes to show how hard it is relative to the level of interest.