Skip to content

Commit 09ae54f

Browse files
committed
feat(iscript) Bug 1812480 - Change file ownership before creating pkgs
1 parent 3afaad8 commit 09ae54f

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

iscript/src/iscript/mac.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,24 +1030,44 @@ async def create_pkg_files(config, sign_config, all_paths, requirements_plist_pa
10301030
cmd_opts = []
10311031
if sign_config.get("pkg_cert_id"):
10321032
cmd_opts = ["--keychain", sign_config["signing_keychain"], "--sign", sign_config["pkg_cert_id"]]
1033+
# Setup app metadata before we chown + pkgbuild
10331034
for app in all_paths:
10341035
# call set_app_path_and_name because we may not have called sign_app() earlier
10351036
set_app_path_and_name(app)
10361037
app.tmp_pkg_path1 = app.app_path.replace(".appex", ".tmp1.pkg").replace(".app", ".tmp1.pkg")
10371038
app.tmp_pkg_path2 = app.app_path.replace(".appex", ".tmp2.pkg").replace(".app", ".tmp2.pkg")
10381039
app.pkg_path = app.app_path.replace(".appex", ".pkg").replace(".app", ".pkg")
10391040
app.pkg_name = os.path.basename(app.pkg_path)
1040-
cmd = (
1041-
"pkgbuild",
1042-
"--install-location",
1043-
"/Applications",
1044-
*cmd_opts,
1045-
"--component",
1046-
app.app_path,
1047-
app.tmp_pkg_path1,
1048-
)
1049-
futures.append(_retry_run_cmd_semaphore(semaphore=semaphore, cmd=cmd, cwd=app.parent_dir))
1050-
await raise_future_exceptions(futures)
1041+
try:
1042+
for app in all_paths:
1043+
# Set app ownership
1044+
await run_command(
1045+
["sudo", "chown", "-R", "root:admin", app.app_path],
1046+
cwd=app.parent_dir,
1047+
exception=IScriptError,
1048+
)
1049+
1050+
# Build pkg
1051+
cmd = (
1052+
"pkgbuild",
1053+
"--install-location",
1054+
"/Applications",
1055+
*cmd_opts,
1056+
"--ownership=preserve",
1057+
"--component",
1058+
app.app_path,
1059+
app.tmp_pkg_path1,
1060+
)
1061+
futures.append(_retry_run_cmd_semaphore(semaphore=semaphore, cmd=cmd, cwd=app.parent_dir))
1062+
await raise_future_exceptions(futures)
1063+
finally:
1064+
# Reset ownership so we can cleanup after
1065+
for app in all_paths:
1066+
await run_command(
1067+
["sudo", "chown", "-R", f"{os.getuid()}:{os.getgid()}", app.app_path],
1068+
cwd=app.parent_dir,
1069+
exception=IScriptError,
1070+
)
10511071
futures = []
10521072
for app in all_paths:
10531073
pb_opts = []

0 commit comments

Comments
 (0)