cavaliergopher / rpm

A Go implementation of the RPM file format
BSD 3-Clause "New" or "Revised" License
172 stars 44 forks source link

Fix Filemode #16

Closed icarus-sparry closed 6 years ago

icarus-sparry commented 6 years ago

Previously the code assumed that you could just cast the syscall.Stat().mode field to create an os.FileMode, but this is not correct. The mode from stat is a 16 bit value made up of a 4 bit enum that gives the type, 3 bits for suid, sgid, and sticky, and 3 sets of 3 bits for permissions. The os.FileMode is a 32 bit value, with the lower 9 matching the permissions bits, but the remaining 23 bits are a bitfield.

There isn't an exported function in the standard library to convert the output (there are things like fillFileStatFromSys which do more), so this includes a small function to do this.

Signed-off-by: Icarus Sparry icarus.w.sparry@intel.com

matthewrsj commented 6 years ago

This solves an issue we were seeing in https://github.com/clearlinux/diva where every file was being reported as a directory. I can confirm that this solves the issue we were seeing.

cavaliercoder commented 6 years ago

Awesome, thanks! Merged.

I suspect this may break on non-Linux platforms, given the syscall constants, but it was broken before and I'm keen for you to get the Linux fix ASAP.