From: Zbigniew Jędrzejewski-Szmek Date: Thu, 7 Oct 2021 14:22:12 +0000 (+0200) Subject: Refactor the setting of the mode of output files X-Git-Tag: v11~33^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F829%2Fhead;p=thirdparty%2Fmkosi.git Refactor the setting of the mode of output files This doesn't change anything, but is a bit nicer to read. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index d40fee4b1..328b7984a 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4167,12 +4167,22 @@ def save_cache(args: CommandLineArguments, root: Path, raw: Optional[str], cache shutil.move(cast(str, root), cache_path) # typing bug, .move() accepts Path -def _link_output(args: CommandLineArguments, oldpath: PathString, newpath: PathString) -> None: +def _link_output( + args: CommandLineArguments, + oldpath: PathString, + newpath: PathString, + mode: int = 0o666, +) -> None: + assert oldpath is not None assert newpath is not None - os.chmod(oldpath, 0o666 & ~args.original_umask) + # Temporary files created by tempfile have mode trimmed to the user. + # After we are done writing files, adjust the mode to the default specified by umask. + os.chmod(oldpath, mode & ~args.original_umask) + os.link(oldpath, newpath) + if args.no_chown: return @@ -4261,8 +4271,7 @@ def link_output_sshkey(args: CommandLineArguments, sshkey: Optional[SomeIO]) -> if sshkey: assert args.output_sshkey with complete_step("Linking private ssh key file…", f"Linked {path_relative_to_cwd(args.output_sshkey)}"): - _link_output(args, sshkey.name, args.output_sshkey) - os.chmod(args.output_sshkey, 0o600) + _link_output(args, sshkey.name, args.output_sshkey, mode=0o600) def link_output_split_root(args: CommandLineArguments, split_root: Optional[SomeIO]) -> None: