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

Fix '~' user source expansion for --copyout #1229

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mock/py/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,9 @@ def run_command(options, args, config_opts, commands, buildroot, state):
dest = args[-1]
sources = []
for arg in args[:-1]:
matches = glob.glob(buildroot.make_chroot_path(arg.replace('~', buildroot.homedir)))
with util.env_var_override("HOME", buildroot.homedir):
arg = os.path.expanduser(arg)
matches = glob.glob(buildroot.make_chroot_path(arg))
if not matches:
log.critical("%s not found", arg)
return 50
Expand Down
19 changes: 19 additions & 0 deletions mock/py/mockbuild/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,3 +1079,22 @@ def nullcontext():
Python 3.6+ compatible because of EL 8
"""
yield None

@contextlib.contextmanager
def env_var_override(name, value):
"""
Temporary set environment variable NAME to VALUE, revert to the previous
state.
"""

oldval = None
if name in os.environ:
oldval = os.environ[name]

os.environ[name] = value
yield

if oldval is None:
del os.environ[name]
else:
os.environ[name] = oldval
4 changes: 4 additions & 0 deletions releng/release-notes-next/expanduser-with-copyout.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Previous versions of Mock mistakenly expanded every `~` occurrence
(tilde character) in the specified source path with `--copyout`. So
files `~/foo~bar.txt` were searched on path `/builddir/foo/builddirbar.txt`
instead of just `/builddir/foo~bar.txt`. Fixes [rhbz#2239035][].