]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Rename --no-chown option to --chown
authorQuentin Deslandes <qde@naccy.de>
Wed, 16 Nov 2022 12:22:08 +0000 (13:22 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 14 Dec 2022 10:09:07 +0000 (11:09 +0100)
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.

NEWS.md
man/mkosi.1
mkosi/__init__.py
mkosi/backend.py
tests/test_config_parser.py

diff --git a/NEWS.md b/NEWS.md
index a4e0ffc599497422169799f0cee3bcbf9e5771b7..208943c871b3b955bbd829cf9bb15fd289e4a169 100644 (file)
--- 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
index 7f472d3c158641fb869f86083b36b57e8b693d19..c1a1a1328da966095cb0582c4705c9ffcf69f2bd 100644 (file)
@@ -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
index dea9ce2016db57ff58fae57f610ac330840c08da..98c72e317d065ddaded7a22b31d3c804792102e0 100644 (file)
@@ -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]:
index 6cca4dd428e2c1982ea33f111598986ae5a251ef..51f5e0cdb098ab3a0329a1dd20a8d721ad3f7b6a 100644 (file)
@@ -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:
index b715f015c0f64493f9c2f6206725044f36460398..79c0e5997df72ccbe71d6f7a1dacbdc34a895785 100644 (file)
@@ -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,