This gives me the name of the file/dir/symlink in question, i.e
who owns it.
However, I found this is a bit long. Anyone knows of a shorter
way? Specifically I wonder if I have to use both Etc. and File.
or if I can just one one of these two.
I didn’t find a quick way to just retrieve the name in class File
though.
This gives me the name of the file/dir/symlink in question, i.e
who owns it.
However, I found this is a bit long. Anyone knows of a shorter
way? Specifically I wonder if I have to use both Etc. and File.
or if I can just one one of these two.
As far as I can see you need both because File.stat only returns the
numeric ID.
However, I found this is a bit long. Anyone knows of a shorter
way? Specifically I wonder if I have to use both Etc. and File.
or if I can just one one of these two.
I didn’t find a quick way to just retrieve the name in class File
though.
That’s about as good as it gets. You can always re-open the File class
if this is something you need on a regular basis:
class File
def self.owner(file)
Etc.getpwuid(stat(file).uid).name
end
end
That’s about as good as it gets. You can always re-open the File class
if this is something you need on a regular basis:
Thanks to both, I guess I will extend File for the project.
I do not know how fast Etc.getpwuid is but I assume it might be slow
because the information has to be retrieved via system calls and
potentially grabbed from persistent storage. If you need this
frequently then you might want to cache entries, e.g.