From: Quentin Deslandes Date: Wed, 16 Nov 2022 12:22:08 +0000 (+0100) Subject: Rename --no-chown option to --chown X-Git-Tag: v15~380 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f275061ebc5247011b7f30b2f810795a4c19a526;p=thirdparty%2Fmkosi.git Rename --no-chown option to --chown Rename --no-chown to --chown and defaults to true. This will make it easier to reason on the code behaviour when this option is used. --- diff --git a/NEWS.md b/NEWS.md index a4e0ffc59..208943c87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # mkosi Changelog +## v15 + +- Rename `--no-chown` to `--chown` and set it to default to `True`, preserving + current behaviour. + ## v14 - Support for Clear Linux was dropped. See https://github.com/systemd/mkosi/pull/1037 diff --git a/man/mkosi.1 b/man/mkosi.1 index 7f472d3c1..c1a1a1328 100644 --- a/man/mkosi.1 +++ b/man/mkosi.1 @@ -693,12 +693,11 @@ This is useful in A/B update scenarios where an existing disk image shall be augmented with a new version of a root or \f[C]/usr\f[R] partition along with its Verity partition and unified kernel. .TP -\f[B]\f[CB]NoChown=\f[B]\f[R], \f[B]\f[CB]--no-chown\f[B]\f[R] +\f[B]\f[CB]Chown=\f[B]\f[R], \f[B]\f[CB]--chown\f[B]\f[R] By default, if \f[C]mkosi\f[R] is run inside a \f[C]sudo\f[R] environment all generated artifacts have their UNIX user/group ownership changed to the user which invoked \f[C]sudo\f[R]. -With this option this may be turned off and all generated files are -owned by \f[C]root\f[R]. +This behaviour can be disabled with \f[C]--chown=no\f[R]. .TP \f[B]\f[CB]TarStripSELinuxContext=\f[B]\f[R], \f[B]\f[CB]--tar-strip-selinux-context\f[B]\f[R] If running on a SELinux-enabled system (Fedora Linux, CentOS, Rocky diff --git a/mkosi/__init__.py b/mkosi/__init__.py index dea9ce201..98c72e317 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3033,7 +3033,7 @@ def save_cache(state: MkosiState, raw: Optional[str], cache_path: Optional[Path] unlink_try_hard(cache_path) shutil.move(cast(str, state.root), cache_path) # typing bug, .move() accepts Path - if not state.config.no_chown: + if state.config.chown: chown_to_running_user(cache_path) @@ -3051,11 +3051,9 @@ def _link_output( os.link(oldpath, newpath) - if config.no_chown: - return - - relpath = path_relative_to_cwd(newpath) - chown_to_running_user(relpath) + if config.chown: + relpath = path_relative_to_cwd(newpath) + chown_to_running_user(relpath) def link_output(state: MkosiState, artifact: Optional[BinaryIO]) -> None: @@ -3257,7 +3255,7 @@ def setup_package_cache(config: MkosiConfig, workspace: Path) -> Path: cache = workspace / "cache" else: cache = config.cache_path - mkdirp_chown_current_user(cache, skip_chown=config.no_chown, mode=0o755) + mkdirp_chown_current_user(cache, chown=config.chown, mode=0o755) return cache @@ -3941,10 +3939,11 @@ def create_parser() -> ArgumentParserMkosi: group.add_argument("--image-version", help="Set version for image") group.add_argument("--image-id", help="Set ID for image") group.add_argument( - "--no-chown", + "--chown", metavar="BOOL", action=BooleanAction, - help="When running with sudo, disable reassignment of ownership of the generated files to the original user", + default=True, + help="When running with sudo, reassign ownership of the generated files to the original user", ) # NOQA: E501 group.add_argument( "--tar-strip-selinux-context", @@ -5653,7 +5652,7 @@ def make_output_dir(config: MkosiConfig) -> None: if config.output_dir is None: return - mkdirp_chown_current_user(config.output_dir, skip_chown=config.no_chown, mode=0o755) + mkdirp_chown_current_user(config.output_dir, chown=config.chown, mode=0o755) def make_build_dir(config: MkosiConfig) -> None: @@ -5661,7 +5660,7 @@ def make_build_dir(config: MkosiConfig) -> None: if config.build_dir is None: return - mkdirp_chown_current_user(config.build_dir, skip_chown=config.no_chown, mode=0o755) + mkdirp_chown_current_user(config.build_dir, chown=config.chown, mode=0o755) def make_cache_dir(config: MkosiConfig) -> None: @@ -5670,7 +5669,7 @@ def make_cache_dir(config: MkosiConfig) -> None: # return on None unreachable code. I can't see right now, why it *should* be # unreachable, so invert the structure here to be on the safe side. if config.cache_path is not None: - mkdirp_chown_current_user(config.cache_path, skip_chown=config.no_chown, mode=0o755) + mkdirp_chown_current_user(config.cache_path, chown=config.chown, mode=0o755) def configure_ssh(state: MkosiState, cached: bool) -> Optional[TextIO]: diff --git a/mkosi/backend.py b/mkosi/backend.py index 6cca4dd42..51f5e0cdb 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -572,7 +572,7 @@ class MkosiConfig: image_version: Optional[str] image_id: Optional[str] hostname: Optional[str] - no_chown: bool + chown: bool tar_strip_selinux_context: bool incremental: bool minimize: bool @@ -1058,7 +1058,7 @@ def chown_to_running_user(path: PathString) -> None: def mkdirp_chown_current_user( path: PathString, *, - skip_chown: bool = False, + chown: bool = True, mode: int = 0o777, exist_ok: bool = True ) -> None: @@ -1072,10 +1072,8 @@ def mkdirp_chown_current_user( path.mkdir(mode=mode, exist_ok=exist_ok) - if skip_chown: - continue - - chown_to_running_user(path) + if chown: + chown_to_running_user(path) def safe_tar_extract(tar: tarfile.TarFile, path: Path=Path("."), *, numeric_owner: bool=False) -> None: diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index b715f015c..79c0e5997 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -97,7 +97,7 @@ class MkosiConfig: "mirror": None, "repository_key_check": True, "mksquashfs_tool": [], - "no_chown": False, + "chown": True, "nspawn_settings": None, "output": None, "output_dir": None,