go - unable to obtain all permission bits -
on shell, have file , change permissions of file sudo chmod 4755 <file>
. upon calling lstat
on file, i'm seeing correct information permissions, has 4755 permission mode.
in golang program, there reason why i'm not getting correct permission mode bits? i'm formatting result fileinfo().mode().perm() incorrectly? upper 3 bits "special"?
thanks help!
short answer: 3 upper bits special , need accessed separately.
long answer: documentation explains 9 (out of 12) least significant bits considered standard unix permissions.
the documentation defines behavior of perm()
function calling:
func (m filemode) perm() filemode perm returns unix permission bits in m.
this means perm not defined return of additional bits looking for.
furthermore, source code shows perm()
function masking value returned filemode()
0777
causing initial 3 bits disregarded.
the modesetuid
, modesetgid
, , modesticky
bits (4, 2, , 1 respectively) must each accessed individually constants of filemode
type. performing own masks.
in order determine whether sticky bit set, example, (fileinfo().mode() & modesticky) != 0
. same applies modesetuid
, modsetgid
.
Comments
Post a Comment