Should os.Chmod accept os.FileMode?

751 views
Skip to first unread message

Evan Shaw

unread,
Jan 14, 2012, 4:02:28 AM1/14/12
to golang-dev
I was just updating some code and this came up. It seems silly to
require a conversion in this code:

info, _ := os.Stat(path)
os.Chmod(path, uint32(info.Mode()|0111))

Is there any reason not to change os.Chmod? I couldn't find any
previous discussion. os.OpenFile has the same issue.

- Evan

Ian Lance Taylor

unread,
Jan 14, 2012, 12:16:09 PM1/14/12
to Evan Shaw, golang-dev
Evan Shaw <eds...@gmail.com> writes:

The current definition of os.Chmod permits the program to set the sticky
bit (01000). Changing the second parameter to FileMode as it stands
today would not permit that. I think that would have to be addressed
one way or another.

Ian

Evan Shaw

unread,
Jan 14, 2012, 2:48:12 PM1/14/12
to Ian Lance Taylor, golang-dev
On Sun, Jan 15, 2012 at 6:16 AM, Ian Lance Taylor <ia...@google.com> wrote:
> The current definition of os.Chmod permits the program to set the sticky
> bit (01000).  Changing the second parameter to FileMode as it stands
> today would not permit that.  I think that would have to be addressed
> one way or another.

Is it just because there's no defined constant for the sticky bit?
Right now one can use an integer literal and it's easy to add a
constant, so I must be missing something.

- Evan

Ian Lance Taylor

unread,
Jan 14, 2012, 3:39:11 PM1/14/12
to Evan Shaw, golang-dev
Evan Shaw <eds...@gmail.com> writes:

In your example of

os.Chmod(path, uint32(info.Mode()|0111))

the sticky bit would be unintentionally cleared.

It's fixable, it just has to be done.

Ian

Rob 'Commander' Pike

unread,
Jan 14, 2012, 3:40:52 PM1/14/12
to Ian Lance Taylor, Evan Shaw, golang-dev

Not very sticky then, is it?

-rob


Russ Cox

unread,
Jan 15, 2012, 1:44:42 PM1/15/12
to Rob 'Commander' Pike, Ian Lance Taylor, Evan Shaw, golang-dev
Yes, I think Chmod and the others should take a FileMode.

Russ

Brad Fitzpatrick

unread,
Jan 18, 2012, 8:33:05 PM1/18/12
to r...@golang.org, Rob 'Commander' Pike, Ian Lance Taylor, Evan Shaw, golang-dev
is this a Go 1 thing? is there a bug?

Evan Shaw

unread,
Jan 18, 2012, 8:57:41 PM1/18/12
to Brad Fitzpatrick, r...@golang.org, Rob 'Commander' Pike, Ian Lance Taylor, golang-dev
On Thu, Jan 19, 2012 at 2:33 PM, Brad Fitzpatrick <brad...@google.com> wrote:
> is this a Go 1 thing? is there a bug?

It's a Go 1 thing and there's no bug as far as I know.

- Evan

Brad Fitzpatrick

unread,
Jan 18, 2012, 8:59:19 PM1/18/12
to Evan Shaw, r...@golang.org, Rob 'Commander' Pike, Ian Lance Taylor, golang-dev
Want to file one?

Evan Shaw

unread,
Jan 18, 2012, 9:05:28 PM1/18/12
to Brad Fitzpatrick, r...@golang.org, Rob 'Commander' Pike, Ian Lance Taylor, golang-dev
On Thu, Jan 19, 2012 at 2:59 PM, Brad Fitzpatrick <brad...@golang.org> wrote:
> Want to file one?

Done: http://code.google.com/p/go/issues/detail?id=2733

- Evan

Reply all
Reply to author
Forward
0 new messages