Skip to content

Commit

Permalink
Fix '~' user source expansion for --copyout
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup authored and xsuchy committed Sep 27, 2023
1 parent 67de90c commit c198b6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mock/py/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,9 @@ def run_command(options, args, config_opts, commands, buildroot):
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][].

0 comments on commit c198b6c

Please sign in to comment.