|
| 1 | +from rpmlint.checks.AbstractCheck import AbstractCheck |
| 2 | + |
| 3 | + |
| 4 | +class AtomicUpdateCheck(AbstractCheck): |
| 5 | + |
| 6 | + """ |
| 7 | + Requirements for atomic updates: |
| 8 | + * All files must be stored inside the snapshot, which is in our case /etc and /usr, not /var, |
| 9 | + /opt, /srv, /usr/local or anything else. |
| 10 | + * (Re)starting daemons is not possible. |
| 11 | + * Modifying files outside of /usr and /etc is not possible. |
| 12 | + * Modifications outside the snapshot have to be done via systemd-tmpfiles and systemd services. |
| 13 | + This check currently only implements checking for files at illegal paths. |
| 14 | + """ |
| 15 | + |
| 16 | + def __init__(self, config, output): |
| 17 | + super().__init__(config, output) |
| 18 | + self.check_ghosts = self.config.configuration['AtomicCheckGhosts'] |
| 19 | + self.allowed_dirs = self.config.configuration['AtomicAllowedDirs'] |
| 20 | + self.disallowed_subdirs = self.config.configuration['AtomicDisallowedSubdirs'] |
| 21 | + |
| 22 | + def check(self, pkg): |
| 23 | + if pkg.is_source: |
| 24 | + return |
| 25 | + |
| 26 | + # Check for files stored outside the snapshot |
| 27 | + self._check_paths(pkg, self.check_ghosts) |
| 28 | + |
| 29 | + def _check_paths(self, pkg, check_ghosts=False): |
| 30 | + for file in pkg.files.keys(): |
| 31 | + if file in pkg.ghost_files: |
| 32 | + continue # Ghosts are only handled if explicitly desired |
| 33 | + if not (self._check_single_path(file)): |
| 34 | + self.output.add_info('E', pkg, 'dir-or-file-outside-snapshot', file) |
| 35 | + if check_ghosts: |
| 36 | + for ghost in pkg.ghost_files: |
| 37 | + if not (self._check_single_path(ghost)): |
| 38 | + self.output.add_info('W', pkg, 'ghost-outside-snapshot', ghost) |
| 39 | + |
| 40 | + def _check_single_path(self, file): |
| 41 | + return ( |
| 42 | + file.startswith(tuple(self.allowed_dirs)) and |
| 43 | + not file.startswith(tuple(self.disallowed_subdirs)) |
| 44 | + ) |
0 commit comments