File permissions w/Dir.mkdir

J

John Joyce

In OS X 10.4.9, Ruby 1.8.4 when I use:
Dir.mkdir(file_name, 755)

The directories created are drop-box, owner-only.
It seems the Dir class expects the leading bit.
So, it should be 0755 and not 755.

When using:
Dir.mkdir(file_name)

Without permissions, it appears to default to 0755.

Just thought this might be useful for some people.
Seems like I read this in the Pickaxe, but I forgot.
It is interesting, since chmod accepts 755 and assumes you mean 0755
Seems to me that Dir should do the same assuming... but doesn't


John Joyce
 
A

Anthony Martinez

--vTfKKTivj/mQoluA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

In OS X 10.4.9, Ruby 1.8.4 when I use:
Dir.mkdir(file_name, 755)
=20
The directories created are drop-box, owner-only.
It seems the Dir class expects the leading bit.
So, it should be 0755 and not 755.
=20
When using:
Dir.mkdir(file_name)
=20
Without permissions, it appears to default to 0755.
=20
Just thought this might be useful for some people.
Seems like I read this in the Pickaxe, but I forgot.
It is interesting, since chmod accepts 755 and assumes you mean 0755
Seems to me that Dir should do the same assuming... but doesn't
=20

Dir.mkdir accepts octal numbers, which is standard notation for this
sort of thing. A leading 0 makes Ruby interpret it as octal. You *could*
say Dir.mkdir(file_name, 493), but that's sick and twisted.=20

Also, without the second argument it defaults to 0777, which will get
modified by the umask. cf lines 912-917 of dir.c in the ruby 1.8.6
source.

The reason chmod on the command line accepts 755 is because it can
assume you mean octal digits. Also, I think I've come across a few
(weirder) chmods that require the leading 0, but that was a long time
ago.
=20
John Joyce
=20
=20
=20

--=20
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++
gives you enough rope to shoot yourself in the foot.

--vTfKKTivj/mQoluA
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGgyBhKaiGM/xGKzQRAqQlAJ9MAF+KJXlM+n2EtX2PH4QE0WufbACgrH9t
k5mUj2YU7TEEunV64eozDKs=
=euBT
-----END PGP SIGNATURE-----

--vTfKKTivj/mQoluA--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,310
Members
47,977
Latest member
MillaDowdy

Latest Threads

Top