Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert orig_environ fix in command controllers #1855

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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