debian-forge/osbuild/util
Christian Kellner 7a923efb1d util/rmrf: handle broken symlinks
The current implementation of `rmtree` will try to fix permissions
when it encounters permission errors during its operation. This is
done by opening the target via `os.open` and then adjusting the
immutable flag and the permission bits. This is a problem when the
target is a broken symlink since open will fail with `ENOENT`. A
simple reproducer of this scenario is:
  $ mkdir subdir
  $ ln -s foo subdir/broken
  $ chmod a-w subdir/
  $ python3 -c 'import osbuild; osbuild.util.rmrf.rmtree("subdir")'

Since subdir is not writable, removing `subdir/broken` will fail
with `EPERM` and the `on_error` callback will try to fix it by
invoking `fixperms` on `subdir/broken` which will in `open` since
the target does not exist (broken symlink).

This is fixed by using `O_NOFOLLOW` to open so we will never open
the target. Instead `open` will fail with `ELOOP`; we ignore that
error and in fact we ignore now all errors from `open` since it
does not matter: if fixing the permissions didn't work `unlink`
will just fail (again) with `EPERM` and for symlinks it actually
doesn't matter since "on Linux the permissions of an ordinary
symbolic link are not used in an operations", see symlinks(7).
2021-12-02 11:38:30 +01:00
..
__init__.py util: mark as module 2020-04-21 17:00:04 +02:00
checksum.py util: add new checksum related utilities 2021-05-12 14:26:16 +02:00
ctx.py util/ctx: extract suppress_oserror() 2020-05-11 18:05:12 +02:00
jsoncomm.py util/jsoncomm: add send_and_recv helper 2021-06-09 18:37:47 +01:00
linux.py util/linux: add helper for BLK_IOC_FLSBUF ioctl 2021-08-13 17:35:32 +02:00
lorax.py utils/lorax: add lorax template related helpers 2021-02-19 14:42:32 +00:00
lvm2.py utils: add lvm2 utility module 2021-08-13 12:20:54 +02:00
osrelease.py util/osrelease: add default os-release paths 2020-10-21 11:13:28 +02:00
ostree.py stages: add org.osbuild.ostree.passwd 2021-08-17 13:53:00 +02:00
path.py util/path: add path checker helper function 2021-06-28 19:07:42 +02:00
rhsm.py util/rhsm: Check if repositories is None before iterating 2021-09-03 20:52:17 +02:00
rmrf.py util/rmrf: handle broken symlinks 2021-12-02 11:38:30 +01:00
selinux.py util/selinux: add gefilecon helper 2020-06-15 20:36:48 +02:00
types.py util: add types module defining PathLike type 2020-07-27 12:50:38 +01:00