debian-forge/osbuild
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
..
formats formats/v2: fix describe for mount without source 2021-11-08 11:26:37 +00:00
util util/rmrf: handle broken symlinks 2021-12-02 11:38:30 +01:00
__init__.py pipeline: remove Assembler class 2021-01-19 10:42:26 +01:00
__main__.py osbuild: always return exit code 2020-10-27 22:04:09 +01:00
api.py api: remove host side arguments facility 2021-07-08 15:01:33 +01:00
buildroot.py buildroot: mask /proc/cmdline 2021-11-30 12:01:13 +01:00
devices.py devices: add device path helper functions 2021-10-30 15:32:44 +01:00
host.py host: check reply_fds before sending them 2021-09-24 12:14:04 +01:00
inputs.py inputs: convert to host service 2021-06-09 18:37:47 +01:00
loop.py loop: helper to call ioctl_blockdev_flushbuf 2021-08-13 17:35:32 +02:00
main_cli.py sources: port to host services 2021-09-22 00:00:20 +02:00
meta.py meta: allow mounts for all stages 2021-10-30 15:32:44 +01:00
monitor.py monitor/log: print pipeline information 2021-02-12 15:55:43 +01:00
mounts.py mounts: include tree directory in arguments 2021-10-30 15:32:44 +01:00
objectstore.py objectstore: use recursive bind mounts 2021-07-09 18:09:37 +01:00
pipeline.py mounts: introduce new mount manager class 2021-10-30 15:32:44 +01:00
remoteloop.py remoteloop: close loop device controller 2021-08-11 20:59:51 +02:00
sources.py sources: pass items via temporary file 2021-09-24 08:27:19 +01:00
treesum.py treesum: handle special device files 2021-02-16 23:00:13 +00:00