I have a file with paths and permissions in POSIX octal notation. The file paths must exist and permissions are checked as per the manifest file. If mismatch, set new filesystem permissions as per manifest. Is there an easy conversion between std::filesystem::perms
and POSIX permissions?
As checked std::filesystem::permissions()
has no integral type overload. The values in perms
are non sequential.
I looked into BitmaskType named requirement, std::to_underlying
and std::underlying_type
.
The current workaround initializes std::array<std::filesystem::perms, 12>
manually with all possible individual (single bit) permissions, but is dependent on the element positions and if upstream makes changes to the perms
enum class
, the code will break.
Iterating over the array works by setting corresponding bits in std::bitset<12>
, checking each bit and casting the bitset
to an unsigned integral type.
This is necessary since std::filesystem::perms
is an enum class
and unable to iterate over.