Skip to content

Commit

Permalink
refactor: Remove follow_symlinks from FileCaps methods
Browse files Browse the repository at this point in the history
Since file capabilities can't be attached to symlinks, just binaries,
this option is useless.
  • Loading branch information
cptpcrd committed Oct 28, 2020
1 parent d362618 commit 7cc08a5
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions pyprctl/file_caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,44 +116,36 @@ def copy(self) -> "FileCaps":
def get_for_file(
cls,
path: Union[int, str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"],
*,
follow_symlinks: bool = True,
) -> "FileCaps":
"""
Retrieves the file capabilities attached to the given file. ``path`` and ``follow_symlinks``
are as for ``os.getxattr()``.
Retrieves the file capabilities attached to the given file. ``path`` is as for
``os.getxattr()``.
"""

return cls._from_data(
os.getxattr(path, ffi.XATTR_NAME_CAPS, follow_symlinks=follow_symlinks)
)
return cls._from_data(os.getxattr(path, ffi.XATTR_NAME_CAPS))

def set_for_file(
self,
path: Union[int, str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"],
*,
follow_symlinks: bool = True,
) -> None:
"""
Sets the file capabilities attached to the given file to the state represented by this
object. ``path`` and ``follow_symlinks`` are as for ``os.setxattr()``.
object. ``path`` is as for ``os.setxattr()``.
"""

os.setxattr(path, ffi.XATTR_NAME_CAPS, self._into_data(), follow_symlinks=follow_symlinks)
os.setxattr(path, ffi.XATTR_NAME_CAPS, self._into_data())

@classmethod
def remove_for_file(
cls,
path: Union[int, str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"],
*,
follow_symlinks: bool = True,
) -> None:
"""
Removes the file capabilities attached to the given file. ``path`` and ``follow_symlinks``
are as for ``os.removexattr()``.
Removes the file capabilities attached to the given file. ``path`` is as for
``os.removexattr()``.
"""

os.removexattr(path, ffi.XATTR_NAME_CAPS, follow_symlinks=follow_symlinks)
os.removexattr(path, ffi.XATTR_NAME_CAPS)

@classmethod
def from_text(cls, text: str) -> "FileCaps":
Expand Down

0 comments on commit 7cc08a5

Please sign in to comment.