[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Find out the name of a user, on a given file/dir/symlink?

Marc Heiler

6/9/2009 2:43:00 PM

Right now I use this:

require 'fileutils'
require 'etc'
require 'pp'

FileUtils.touch 'test'

name = Etc.getpwuid(File.stat('test').uid).name

puts name


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.
--
Posted via http://www.ruby-....

8 Answers

Debbie

5/17/2009 2:39:00 AM

0

On May 16, 7:43 pm, fvicar...@aol.com wrote:
> On May 16, 5:06 pm, DAFG3...@aol.com wrote:
>
> > On May 16, 6:27 pm, fvicar...@aol.com wrote:
>
> > > Was Liev Shriber in any of the first three X-Men movies?
>
> > I didn't think so...so I checked IMDb and according to them...nope.
>
> MINOR XMEN SPOLIAGE WARNING
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
>
> Someone much nerdier than myself told me there was some big reveal at
> the end of the new one that tied Liev to "his charcter" in the
> earelier movies.  If so, I missed it.  Same person told me Ian
> McKellan made a surprise brief appearance at the end of hte new
> one....also didn't happen.

I'm trying to remember now if I saw him at the end or not. I know
there was a point at the very end where I said...That's Professor X!
But I can't remember if it was actually Ian M. or a younger actor
portraying a younger Prof. X. I don't know what the big reveal at the
end that tied him to his character really means...

I'll ask my oldest son if he remembers Prof. X at the end...he's a big
X-Men buff....I'm just more of a Wolverine fan. : )

THULL=

5/18/2009 12:00:00 PM

0

On May 16, 10:39 pm, DAFG3...@aol.com wrote:
> On May 16, 7:43 pm, fvicar...@aol.com wrote:
>
>
>
> > On May 16, 5:06 pm, DAFG3...@aol.com wrote:
>
> > > On May 16, 6:27 pm, fvicar...@aol.com wrote:
>
> > > > Was Liev Shriber in any of the first three X-Men movies?
>
> > > I didn't think so...so I checked IMDb and according to them...nope.
>
> > MINOR XMEN SPOLIAGE WARNING
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
> > -
>
> > Someone much nerdier than myself told me there was some big reveal at
> > the end of the new one that tied Liev to "his charcter" in the
> > earelier movies.  If so, I missed it.  Same person told me Ian
> > McKellan made a surprise brief appearance at the end of hte new
> > one....also didn't happen.
>
> I'm trying to remember now if I saw him at the end or not.  I know
> there was a point at the very end where I said...That's Professor X!
> But I can't remember if it was actually Ian M. or a younger actor
> portraying a younger Prof. X.  I don't know what the big reveal at the
> end that tied him to his character really means...
>
> I'll ask my oldest son if he remembers Prof. X at the end...he's a big
> X-Men buff....I'm just more of a Wolverine fan.  : )


Prof. X landed one of his planes and told all of the young mutants to
come with him, there is no reason to be afraid. It was Ian M. too.

stuthalblum@comcast.net

5/18/2009 3:19:00 PM

0

On May 18, 7:59 am, "THULL=" <thu...@columbus.rr.com> wrote:
> On May 16, 10:39 pm, DAFG3...@aol.com wrote:
>
>
>
>
>
> > On May 16, 7:43 pm, fvicar...@aol.com wrote:
>
> > > On May 16, 5:06 pm, DAFG3...@aol.com wrote:
>
> > > > On May 16, 6:27 pm, fvicar...@aol.com wrote:
>
> > > > > Was Liev Shriber in any of the first three X-Men movies?
>
> > > > I didn't think so...so I checked IMDb and according to them...nope.
>
> > > MINOR XMEN SPOLIAGE WARNING
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
> > > -
>
> > > Someone much nerdier than myself told me there was some big reveal at
> > > the end of the new one that tied Liev to "his charcter" in the
> > > earelier movies.  If so, I missed it.  Same person told me Ian
> > > McKellan made a surprise brief appearance at the end of hte new
> > > one....also didn't happen.
>
> > I'm trying to remember now if I saw him at the end or not.  I know
> > there was a point at the very end where I said...That's Professor X!
> > But I can't remember if it was actually Ian M. or a younger actor
> > portraying a younger Prof. X.  I don't know what the big reveal at the
> > end that tied him to his character really means...
>
> > I'll ask my oldest son if he remembers Prof. X at the end...he's a big
> > X-Men buff....I'm just more of a Wolverine fan.  : )
>
> Prof. X landed one of his planes and told all of the young mutants to
> come with him, there is no reason to be afraid. It was Ian M. too.- Hide quoted text -
>
> - Show quoted text -

Ian McKellan played Magneto in the 3 X-Men movies. He is not in the
new Wolverine film.

Patrick Stewart is, playing Professor X.

Debbie

5/19/2009 12:23:00 AM

0

On May 18, 10:19 am, "stuthalb...@comcast.net"
<stuthalb...@comcast.net> wrote:
> On May 18, 7:59 am, "THULL=" <thu...@columbus.rr.com> wrote:
>
>
>
> > On May 16, 10:39 pm, DAFG3...@aol.com wrote:
>
> > > On May 16, 7:43 pm, fvicar...@aol.com wrote:
>
> > > > On May 16, 5:06 pm, DAFG3...@aol.com wrote:
>
> > > > > On May 16, 6:27 pm, fvicar...@aol.com wrote:
>
> > > > > > Was Liev Shriber in any of the first three X-Men movies?
>
> > > > > I didn't think so...so I checked IMDb and according to them...nope.
>
> > > > MINOR XMEN SPOLIAGE WARNING
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
> > > > -
>
> > > > Someone much nerdier than myself told me there was some big reveal at
> > > > the end of the new one that tied Liev to "his charcter" in the
> > > > earelier movies.  If so, I missed it.  Same person told me Ian
> > > > McKellan made a surprise brief appearance at the end of hte new
> > > > one....also didn't happen.
>
> > > I'm trying to remember now if I saw him at the end or not.  I know
> > > there was a point at the very end where I said...That's Professor X!
> > > But I can't remember if it was actually Ian M. or a younger actor
> > > portraying a younger Prof. X.  I don't know what the big reveal at the
> > > end that tied him to his character really means...
>
> > > I'll ask my oldest son if he remembers Prof. X at the end...he's a big
> > > X-Men buff....I'm just more of a Wolverine fan.  : )
>
> > Prof. X landed one of his planes and told all of the young mutants to
> > come with him, there is no reason to be afraid. It was Ian M. too.- Hide quoted text -
>
> > - Show quoted text -
>
> Ian McKellan played Magneto in the 3 X-Men movies.  He is not in the
> new Wolverine film.
>
> Patrick Stewart is, playing Professor X.

Yep..you are right...Patrick Stuart is Prof. X. I just couldn't
remember from the movie if it was actually Stuart at the end of hte
movie or not...I thought it was because I remember blurting
out.."Professor X!" I kinda saw the movie a lil early...

Robert Klemme

6/9/2009 3:47:00 PM

0

2009/6/9 Marc Heiler <shevegen@linuxmail.org>:
> Right now I use this:
>
> require 'fileutils'
> require 'etc'
> require 'pp'
>
> FileUtils.touch 'test'
>
> name = Etc.getpwuid(File.stat('test').uid).name
>
> puts name
>
>
> 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.

irb(main):008:0> st = File.stat "."
=> #<File::Stat dev=0x50a951b9, ino=6755399441101867, mode=040755,
nlink=9, uid=14366, gid=10513, rdev=0x50a951b9, size=0, blksize=65536,
blocks=0, atime=2009-06-09 17:44:07 +0100, mtime=2009-06-09 17:35:03
+0100, ctime=2009-06-09 17:35:03 +0100>
irb(main):009:0> st.owned?
=> true
irb(main):010:0> st.uid
=> 14366
irb(main):011:0>

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...

Daniel Berger

6/9/2009 3:48:00 PM

0



> -----Original Message-----
> From: shevegen@linuxmail.org [mailto:shevegen@linuxmail.org]
> Sent: Tuesday, June 09, 2009 8:43 AM
> To: ruby-talk ML
> Subject: Find out the name of a user, on a given file/dir/symlink?
>=20
> Right now I use this:
>=20
> require 'fileutils'
> require 'etc'
> require 'pp'
>=20
> FileUtils.touch 'test'
>=20
> name =3D Etc.getpwuid(File.stat('test').uid).name
>=20
> puts name
>=20
>=20
> This gives me the name of the file/dir/symlink in question, i.e
> who owns it.
>=20
> 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.
>=20
> 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

Regards,

Dan




Marc Heiler

6/9/2009 3:57:00 PM

0

> 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.

Cheers.
--
Posted via http://www.ruby-....

Robert Klemme

6/10/2009 11:43:00 AM

0

2009/6/9 Marc Heiler <shevegen@linuxmail.org>:
>> 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.

USER_NAME = Hash.new {|h,uid| h[uid] = uid ? Etc.getpwuid(uid).name :
"<unknown>"}

files.each do |f|
puts f, USER_NAME[File.stat(f).uid]
end

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...