Skip to content

Commit

Permalink
Merge pull request #1855 from Chris-Peterson444/undo-os-environ-changes
Browse files Browse the repository at this point in the history
Revert orig_environ fix in command controllers
  • Loading branch information
Chris-Peterson444 committed Oct 25, 2023
2 parents a6708aa + 6c27d65 commit 4dfdc80
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 103 deletions.
12 changes: 1 addition & 11 deletions subiquity/server/controllers/cmdlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import asyncio
import os
import shlex
import shutil
from typing import List, Sequence, Union

import attr
Expand All @@ -26,7 +25,7 @@
from subiquity.server.controller import NonInteractiveController
from subiquitycore.async_helpers import run_bg_task
from subiquitycore.context import with_context
from subiquitycore.utils import arun_command, orig_environ
from subiquitycore.utils import arun_command


@attr.s(auto_attribs=True)
Expand Down Expand Up @@ -79,15 +78,6 @@ async def run(self, context):
env = self.env()
for i, cmd in enumerate(tuple(self.builtin_cmds) + tuple(self.cmds)):
desc = cmd.desc()

# If the path to the command isn't found on the snap we should
# drop the snap specific environment variables.
command = shlex.split(desc)[0]
path = shutil.which(command)
if path is not None:
if not path.startswith("/snap"):
env = orig_environ(env)

with context.child("command_{}".format(i), desc):
args = cmd.as_args_list()
if self.syslog_id:
Expand Down
84 changes: 0 additions & 84 deletions subiquity/server/controllers/tests/test_cmdlist.py

This file was deleted.

13 changes: 5 additions & 8 deletions subiquitycore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import random
import subprocess
from typing import Any, Dict, List, Optional, Sequence
from typing import Any, Dict, List, Sequence

log = logging.getLogger("subiquitycore.utils")

Expand All @@ -35,18 +35,15 @@ def _clean_env(env, *, locale=True):
return env


def orig_environ(env: Optional[Dict[str, str]]) -> Dict[str, str]:
def orig_environ(env):
"""Generate an environment dict that is suitable for use for running
programs that live outside the snap."""

if env is None:
env: Dict[str, str] = os.environ

ret: Dict[str, str] = env.copy()

env = os.environ
ret = env.copy()
for key, val in env.items():
if key.endswith("_ORIG"):
key_to_restore: str = key[: -len("_ORIG")]
key_to_restore = key[: -len("_ORIG")]
if val:
ret[key_to_restore] = val
else:
Expand Down

0 comments on commit 4dfdc80

Please sign in to comment.