fix: preserve literal installer bin directory paths

This commit is contained in:
shoemoney 2026-11-28 00:01:10 -06:00
parent 0314426f1e
commit 582085b94e
No known key found for this signature in database
2 changed files with 40 additions and 1 deletions

View file

@ -100,7 +100,10 @@ if [ -z "$BIN_DIR" ]; then
BIN_DIR=$def
fi
fi
BIN_DIR=$(eval echo "$BIN_DIR") # expand a leading ~
# Expand only a leading ~/; keep the rest of the path literal.
case "$BIN_DIR" in
'~/'*) BIN_DIR="$HOME/${BIN_DIR#\~/}" ;;
esac
SUDO=""
if ! mkdir -p "$BIN_DIR" 2>/dev/null || ! [ -w "$BIN_DIR" ]; then

View file

@ -10,6 +10,42 @@ INSTALLER = Path(__file__).resolve().parents[1] / 'install.sh'
class InstallTest(unittest.TestCase):
def test_bin_dir_is_literal(self):
for mode in ('flag', 'env'):
for case in ('spaces', 'tilde', 'substitution', 'backticks', 'special'):
with self.subTest(mode=mode, case=case), tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
home = root / 'home directory'
home.mkdir()
source = root / 'devbox-fixture'
source.write_text('#!/bin/sh\necho devbox-fixture\n')
source.chmod(0o755)
marker = root / 'executed'
paths = {
'spaces': str(root / ' two spaces '),
'tilde': '~/two spaces/bin',
'substitution': str(root / f'$(touch {marker})'),
'backticks': str(root / f'`touch {marker}`'),
'special': str(root / 'literal \'single\' "double" ; & $HOME * ? [abc] \\ ~'),
}
requested = paths[case]
dest = home / requested[2:] if requested.startswith('~/') else Path(requested)
env = dict(os.environ)
for key in ('DEVBOX_INSTALL_HUB', 'DEVBOX_INSTALL_MCPD_PLUGIN', 'DEVBOX_BIN_DIR'):
env.pop(key, None)
env.update(HOME=str(home), TMPDIR=str(root), DEVBOX_BIN=str(source))
args = ['sh', str(INSTALLER), '--no-service']
if mode == 'flag':
args += ['--bin-dir', requested]
else:
env['DEVBOX_BIN_DIR'] = requested
result = subprocess.run(args, cwd=root, env=env, capture_output=True, text=True, timeout=10)
self.assertFalse(marker.exists(), 'bin directory input executed a command')
self.assertEqual(result.returncode, 0, result.stderr)
self.assertTrue((dest / 'devbox').is_file(), f'missing literal destination: {dest!s}\n{result.stdout}')
self.assertEqual({p.name for p in dest.iterdir()}, {'devbox'})
self.assertEqual(subprocess.check_output([str(dest / 'devbox')], text=True), 'devbox-fixture\n')
def test_optional_plugin(self):
for mode in ('default', 'flag', 'env'):
with self.subTest(mode=mode), tempfile.TemporaryDirectory() as tmp: