fix(bionic): start a program outside the prefix from a drive whose root Android lets Wine open

This commit is contained in:
The412Banner committed 2026-12-03 14:22:50 +00:00
1 parent f9eeef44ed
commit e6370e1ff7
2 files changed
+93

No files matched your search

+27
View File
@@ -224,6 +224,32 @@ drive_z() {
rm -f "$z" && ln -s / "$z" && echo "$(date +%H:%M:%S) drive z: -> / (was ${old:-missing})"
}
program_drive() {
dev=$COMPAT/pfx/dosdevices
case "$EXE" in /*) ;; *) return 0 ;; esac
[ -d "$dev" ] || return 0
dir=${EXE%/*}
top=$dir
ls "$top" > /dev/null 2>&1 || return 0
while [ "$top" != / ]; do
up=${top%/*}; up=${up:-/}
ls "$up" > /dev/null 2>&1 || break
top=$up
done
[ "$top" = / ] && return 0
for l in "$dev"/[a-y]:; do
[ -L "$l" ] || continue
t=$(readlink "$l"); t=${t%/}
case "$t" in /?*) ;; *) continue ;; esac
case "$dir/" in "$t"/*) case "$t/" in "$top"/*) return 0 ;; esac ;; esac
done
for x in d e f g h i j k l m n o p q r t u v w x y; do
{ [ -e "$dev/$x:" ] || [ -L "$dev/$x:" ]; } && continue
ln -s "$top" "$dev/$x:" && echo "$(date +%H:%M:%S) drive $x: -> $top (Android does not let Wine open Z:'s root)"
return 0
done
}
prepare_prefix() {
P=$COMPAT/pfx
drive_z "$P"
@@ -344,6 +370,7 @@ if [ $dead -gt 0 ]; then
fi
prepare_prefix
program_drive
# FEX keeps translated code per program in the prefix (AppData/Local/fex-emu/DiskCache) and reuses it with whatever FEX
# runs the prefix next. Code cached by another FEX build (DroidDeck-Proton's, or a different FEX picked in the
+66
View File
@@ -191,6 +191,72 @@ class PrefixFromProton(unittest.TestCase):
self.assertIn('export WINE_NEW_NDIS=${WINE_NEW_NDIS:-1}', LAUNCH.read_text())
class ProgramDrive(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.addCleanup(self.tmp.cleanup)
base = Path(self.tmp.name)
self.compat = base / 'compatdata/2489251740'
self.drives = self.compat / 'pfx/dosdevices'
self.drives.mkdir(parents=True)
os.symlink('../drive_c', self.drives / 'c:')
os.symlink('/', self.drives / 'z:')
self.storage = base / 'storage/emulated/0'
self.game = self.storage / 'Windows Games/PG Scene Viewer'
self.game.mkdir(parents=True)
self.bin = base / 'bin'
self.bin.mkdir()
ls = self.bin / 'ls'
ls.write_text('#!/bin/sh\nfor a; do case "$a" in -*) continue ;; esac\n'
' case "$a/" in "$OPENS"/*) ;; *) exit 1 ;; esac; done\nexec %s "$@"\n' % shutil.which('ls'))
ls.chmod(0o755)
def run_drive(self, exe, opens):
text = LAUNCH.read_text()
function = text[text.index('program_drive() {'):text.index('\nprepare_prefix() {')]
env = dict(os.environ, COMPAT=str(self.compat), EXE=str(exe), OPENS=str(opens),
PATH='%s:%s' % (self.bin, os.environ['PATH']))
return subprocess.run(['sh', '-c', function + '\nprogram_drive'], env=env,
capture_output=True, text=True, check=True).stdout
def links(self):
return {p.name: os.readlink(p) for p in self.drives.iterdir()}
def test_a_program_under_folders_android_refuses_gets_a_drive_of_its_own(self):
exe = self.game / 'Party Games.exe'
out = self.run_drive(exe, self.storage)
self.assertIn('drive d: -> %s' % self.storage, out)
self.assertEqual({'c:': '../drive_c', 'z:': '/', 'd:': str(self.storage)}, self.links())
self.assertEqual('', self.run_drive(exe, self.storage))
self.assertEqual(3, len(self.links()))
def test_taken_letters_and_the_steam_drive_are_skipped(self):
for name in ('d:', 'e:', 'f:', 'g:', 'h:', 'i:', 'j:', 'k:', 'l:', 'm:', 'n:', 'o:', 'p:', 'q:', 'r:'):
os.symlink('/nonexistent/' + name[0], self.drives / name)
self.run_drive(self.game / 'Party Games.exe', self.storage)
self.assertNotIn('s:', self.links())
self.assertEqual(str(self.storage), self.links()['t:'])
def test_a_drive_that_already_holds_the_program_is_kept(self):
os.symlink(str(self.storage / 'Windows Games'), self.drives / 's:')
self.assertEqual('', self.run_drive(self.game / 'Party Games.exe', self.storage))
self.assertEqual({'c:', 'z:', 's:'}, set(self.links()))
def test_a_drive_above_the_openable_folders_does_not_count(self):
os.symlink(str(self.storage.parent), self.drives / 'e:')
self.run_drive(self.game / 'Party Games.exe', self.storage)
self.assertEqual(str(self.storage), self.links()['d:'])
def test_windows_paths_bare_names_and_an_open_root_add_no_drive(self):
self.assertEqual('', self.run_drive('D:\\Games\\game.exe', self.storage))
self.assertEqual('', self.run_drive('cmd.exe', self.storage))
self.assertEqual('', self.run_drive(self.game / 'Party Games.exe', ''))
self.assertEqual({'c:', 'z:'}, set(self.links()))
def test_the_launch_adds_it_after_the_prefix_is_ready(self):
self.assertIn('\nprepare_prefix\nprogram_drive\n', LAUNCH.read_text())
class StorePaths(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()