# HG changeset patch # User Alain Leufroy # Date 1614933275 -3600 # Fri Mar 05 09:34:35 2021 +0100 # Node ID 78c3464d21b0d278dc735c3cb5c63a7d822f7ff1 # Parent e2a0270f2d92e506ffe0bd42be7f7f25756fa1b9 editer: user is the boss In a few situation, OverlayFS is ok with that. If the user insists, let's do it. diff --git a/overlayctl b/overlayctl --- a/overlayctl +++ b/overlayctl @@ -604,19 +604,20 @@ Popen(cmd, shell=True).wait() -def editer(name, appended=None, prepended=None, removed=None): +def editer(name, appended=None, prepended=None, removed=None, keep_others=False): """Ask user to edit lowers of the given overlay name, rewrite the metadata and unit files accordingly, finaly retart systemd units of the edited overlay. """ layer = build_layer(name) - to_stop = [layer for layer in _iter_descendants(layer) if layer.automountunit.is_active()] - if to_stop: - # XXX automatic stop/start - logger.error( - 'You should prefere to stop the following overlays: \n\n%s\n', - ', '.join(x.name for x in to_stop)) - return + if not keep_others: + to_stop = [layer for layer in _iter_descendants(layer) if layer.automountunit.is_active()] + if to_stop: + # XXX automatic stop/start + logger.error( + 'You should prefere to stop the following overlays: \n\n%s\n', + ', '.join(x.name for x in to_stop)) + return if not appended and not prepended and not removed: with NamedTemporaryFile() as fobj: fobj.write(b'# -*- encoding: utf-8 -*-\n') @@ -1018,6 +1019,13 @@ '-d', '--delete', action='append', help="append the following names", ) edit.add_argument( + '--keep-others', '-K', + action='store_true', + default=False, + help=('do not check if descendant overlays are started ' + '(may produce inconsistant behaviours)') + ) + edit.add_argument( 'mountdir', metavar='MOUNTDIR', help=( @@ -1027,7 +1035,7 @@ ) def _editer(args): - editer(args.mountdir, args.append, args.prepend, args.delete) + editer(args.mountdir, args.append, args.prepend, args.delete, args.keep_others) edit.set_defaults(func=_editer) diff --git a/test_overlayctl.py b/test_overlayctl.py --- a/test_overlayctl.py +++ b/test_overlayctl.py @@ -482,6 +482,17 @@ overlayctl.editer('lower', removed=['base']) self.check_mount_unit('lower', [self.get_mount_dir('base')]) + def test_editing_layer_with_active_descendant(self): + # Because OverlayFS does not like it, we protect users from + # having broken mount point. But if the user is ok with that, let's do it. + self.get_mount_dir('base').mkdir() + overlayctl.creater('lower', ['base']) + overlayctl.creater('layer', ['lower']) + self.systemctl.reset_mock() + self.systemctl.status.return_value = {'Active': 'active'} + overlayctl.editer('lower', removed=['base'], keep_others=True) + self.check_mount_unit('lower', []) + class TestMove(BaseTest): """Tests for the `move` command."""