mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
fix: games on an SD card install faster and Battle.net can read the card's volume (#2379)
A Battle.net library on another volume is reached through its own drive letter, so the Agent's volume query succeeds. The proot fast path keeps folder handles for FUSE-backed libraries. Supersedes #2377.
This commit is contained in:
1 parent
1d247d212b
commit
3b6d13a8d7
6 files changed
+883
-36
No files matched your search
@@ -198,6 +198,155 @@ class ConfigAndMenuTest(Temp):
|
||||
self.assertEqual(path.stat().st_mtime_ns, mtime)
|
||||
|
||||
|
||||
class DriveTest(Temp):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.root = str(self.tmp / "Steam")
|
||||
self.devices = Path(BNET["dosdevices"](self.root))
|
||||
self.card = self.tmp / "card"
|
||||
self.library = self.card / "Games/Battle.net"
|
||||
self.library.mkdir(parents=True)
|
||||
self.running = []
|
||||
patcher = mock.patch.dict(BNET, {"say": lambda message: None, "wine_processes": lambda pfx, proc="/proc": list(self.running),
|
||||
"volume_root": lambda path: str(self.card) if BNET["inside"](path, str(self.card)) else "/"})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def test_a_volume_ends_where_the_device_changes(self):
|
||||
devices = {"/": 1, "/mnt": 1, "/mnt/card": 7, "/mnt/card/Games": 7, "/mnt/card/Games/Battle.net": 7, "/root": 1, "/root/Games": 1}
|
||||
with mock.patch.object(os, "stat", lambda path: mock.Mock(st_dev=devices[path])):
|
||||
volume_root = runpy.run_path(str(BIN / "droiddeck-battlenet"))["volume_root"]
|
||||
self.assertEqual(volume_root("/mnt/card/Games/Battle.net"), "/mnt/card")
|
||||
self.assertEqual(volume_root("/mnt/card"), "/mnt/card")
|
||||
self.assertEqual(volume_root("/root/Games"), "/")
|
||||
self.assertEqual(volume_root("/"), "/")
|
||||
|
||||
def test_a_library_on_the_root_volume_keeps_its_path_and_gets_no_drive(self):
|
||||
library = self.tmp / "root/Games/Battle.net"
|
||||
library.mkdir(parents=True)
|
||||
self.assertEqual(BNET["install_path"](self.root, str(library) + "/"), "Z:" + str(library))
|
||||
self.assertFalse(self.devices.exists())
|
||||
|
||||
def test_a_library_on_another_volume_gets_a_drive_at_the_volume_root(self):
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "D:\\Games\\Battle.net")
|
||||
self.assertEqual(os.readlink(self.devices / "d:"), str(self.card))
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library / "World of Warcraft")), "D:\\Games\\Battle.net\\World of Warcraft")
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.card)), "D:\\")
|
||||
self.assertEqual(sorted(os.listdir(self.devices)), ["d:"])
|
||||
|
||||
def test_drives_in_use_and_the_ones_proton_owns_are_left_alone(self):
|
||||
self.devices.mkdir(parents=True)
|
||||
os.symlink("/somewhere/else", self.devices / "d:")
|
||||
os.symlink(str(self.card), self.devices / "s:")
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "E:\\Games\\Battle.net")
|
||||
self.assertEqual(os.readlink(self.devices / "d:"), "/somewhere/else")
|
||||
for letter in BNET["DRIVES"]:
|
||||
if not os.path.lexists(self.devices / (letter + ":")):
|
||||
os.symlink("/somewhere/else", self.devices / (letter + ":"))
|
||||
os.unlink(self.devices / "e:")
|
||||
os.symlink("/somewhere/else", self.devices / "e:")
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "Z:" + str(self.library))
|
||||
self.assertNotIn("s", BNET["DRIVES"])
|
||||
self.assertNotIn("t", BNET["DRIVES"])
|
||||
|
||||
def test_a_running_prefix_gets_no_new_drive_but_uses_the_ones_it_started_with(self):
|
||||
self.running = [(5, ["C:\\Program Files (x86)\\Battle.net\\Battle.net.exe"])]
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "Z:" + str(self.library))
|
||||
self.assertFalse(self.devices.exists())
|
||||
self.running = []
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "D:\\Games\\Battle.net")
|
||||
self.running = [(5, ["C:\\Program Files (x86)\\Battle.net\\Battle.net.exe"])]
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "D:\\Games\\Battle.net")
|
||||
|
||||
def test_a_drive_mapped_inside_the_volume_is_reused(self):
|
||||
self.devices.mkdir(parents=True)
|
||||
os.symlink(str(self.card / "Games"), self.devices / "g:")
|
||||
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "G:\\Battle.net")
|
||||
self.assertEqual(sorted(os.listdir(self.devices)), ["g:"])
|
||||
|
||||
def test_the_config_stores_the_drive_path_once(self):
|
||||
path = self.tmp / ("Steam/steamapps/compatdata/%s/pfx/drive_c/users/steamuser/AppData/Roaming/Battle.net/Battle.net.config"
|
||||
% BNET["APP_ID"])
|
||||
BNET["write_config"](self.root)
|
||||
self.assertEqual(BNET["write_config"](self.root, str(self.library)), "library")
|
||||
self.assertEqual(json.loads(path.read_text())["Client"]["Install"]["DefaultInstallPath"], "D:\\Games\\Battle.net")
|
||||
self.assertIsNone(BNET["write_config"](self.root, str(self.library)))
|
||||
|
||||
def test_registered_paths_resolve_through_their_drive(self):
|
||||
BNET["install_path"](self.root, str(self.library))
|
||||
self.assertEqual(BNET["windows_path"](self.root, "D:/Games/Battle.net/World of Warcraft"),
|
||||
str(self.library / "World of Warcraft"))
|
||||
self.assertEqual(BNET["windows_path"](self.root, "Z:\\mnt\\card\\World of Warcraft"), "/mnt/card/World of Warcraft")
|
||||
self.assertEqual(BNET["windows_path"](self.root, "C:/Program Files (x86)/World of Warcraft"),
|
||||
os.path.join(BNET["drive_c"](self.root), "Program Files (x86)/World of Warcraft"))
|
||||
self.assertIsNone(BNET["windows_path"](self.root, "E:/Games/X"))
|
||||
self.assertIsNone(BNET["windows_path"](self.root, "D:/../etc"))
|
||||
self.assertEqual(BNET["windows_path"](self.root, "D:\\"), str(self.library.parent.parent))
|
||||
|
||||
def field(self, number, value):
|
||||
varint = BNET["encode_varint"]
|
||||
return varint(number << 3 | 2) + varint(len(value)) + value
|
||||
|
||||
def product(self, uid, folder, filler=b""):
|
||||
settings = self.field(1, folder.encode()) + self.field(2, b"us") + b"\x18\x02" + filler
|
||||
return self.field(1, self.field(1, uid.encode()) + self.field(2, uid.encode()) + self.field(3, settings)
|
||||
+ b"\x21" + bytes(8) + b"\x2d" + bytes(4))
|
||||
|
||||
def database(self, *products):
|
||||
path = Path(BNET["drive_c"](self.root)) / "ProgramData/Battle.net/Agent/product.db"
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(b"".join(products) + self.field(7, b"tail"))
|
||||
path.chmod(0o600)
|
||||
return path
|
||||
|
||||
def test_games_registered_through_the_root_drive_move_to_their_volume_drive(self):
|
||||
game = self.library / "World of Warcraft"
|
||||
game.mkdir()
|
||||
other = self.tmp / "root/Games/Other"
|
||||
other.mkdir(parents=True)
|
||||
client = self.product("battle.net", "C:/Program Files (x86)/Battle.net")
|
||||
local = self.product("other", "Z:" + str(other))
|
||||
gone = self.product("gone", "Z:" + str(self.card / "Missing"))
|
||||
path = self.database(client, self.product("wow", "Z:" + str(game), bytes(200)), local, gone)
|
||||
self.assertTrue(BNET["move_installs"](self.root))
|
||||
self.assertEqual(path.read_bytes(), client + self.product("wow", "D:/Games/Battle.net/World of Warcraft", bytes(200))
|
||||
+ local + gone + self.field(7, b"tail"))
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(os.readlink(self.devices / "d:"), str(self.card))
|
||||
self.assertFalse(BNET["move_installs"](self.root))
|
||||
|
||||
def test_registrations_stay_while_the_prefix_runs_or_the_database_is_unreadable(self):
|
||||
game = self.library / "World of Warcraft"
|
||||
game.mkdir()
|
||||
path = self.database(self.product("wow", "Z:" + str(game)))
|
||||
before = path.read_bytes()
|
||||
self.running = [(5, ["C:\\ProgramData\\Battle.net\\Agent\\Agent.exe"])]
|
||||
self.assertFalse(BNET["move_installs"](self.root))
|
||||
self.assertEqual(path.read_bytes(), before)
|
||||
self.running = []
|
||||
for broken in (before[:-3], b"\x0a\xff", b"\x0b\x01"):
|
||||
path.write_bytes(broken)
|
||||
self.assertFalse(BNET["move_installs"](self.root))
|
||||
self.assertEqual(path.read_bytes(), broken)
|
||||
os.unlink(path)
|
||||
self.assertFalse(BNET["move_installs"](self.root))
|
||||
|
||||
def test_a_database_written_while_it_was_being_read_is_left_as_written(self):
|
||||
game = self.library / "World of Warcraft"
|
||||
game.mkdir()
|
||||
path = self.database(self.product("wow", "Z:" + str(game)))
|
||||
newer = path.read_bytes() + self.field(7, b"newer")
|
||||
|
||||
def processes(pfx, proc="/proc"):
|
||||
path.write_bytes(newer)
|
||||
return []
|
||||
|
||||
with mock.patch.dict(BNET, {"wine_processes": processes}):
|
||||
self.assertFalse(BNET["move_installs"](self.root))
|
||||
self.assertEqual(path.read_bytes(), newer)
|
||||
self.assertTrue(BNET["move_installs"](self.root))
|
||||
|
||||
|
||||
class GamepadTest(Temp):
|
||||
def registry(self, *entries):
|
||||
rows = ["WINE REGISTRY Version 2"]
|
||||
@@ -772,7 +921,7 @@ class Harness(Temp):
|
||||
"stop": lambda processes, wait=0: self.calls.append(("stop", sorted(pid for pid, _ in processes))),
|
||||
"start": lambda exe, verb=None: self.calls.append(("start", os.path.basename(exe), verb)) or self.Proton(),
|
||||
"spawn": lambda program, verb, args=(): self.calls.append(("spawn", os.path.basename(program), verb, list(args))),
|
||||
"acquire": lambda folder=None: self.lock,
|
||||
"acquire": lambda folder=None: self.lock, "volume_root": lambda path: "/",
|
||||
"POLL": 0, "READY_SETTLE": 0, "GAME_GRACE": 0, "CLIENT_WAIT": 0,
|
||||
})
|
||||
patcher.start()
|
||||
@@ -1170,6 +1319,7 @@ class AgentTest(Temp):
|
||||
script = BNET["AGENT_SCRIPT"]
|
||||
self.assertIn("port = a(0), action = a(1), uid = a(2), product = a(3), dir = a(4)", script)
|
||||
self.assertIn("lang = a(5), country = a(6), region = a(7), out = a(8)", script)
|
||||
self.assertIn(r'''"game_dir":"' + dir.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '","geo''', script)
|
||||
self.assertIn('"--internalclienttools"', (BIN / "droiddeck-battlenet").read_text())
|
||||
|
||||
def test_the_driver_asks_blizzards_chinese_repository_for_chinese_installs(self):
|
||||
@@ -1230,6 +1380,40 @@ class AgentJobTest(Harness):
|
||||
self.assertEqual([kind for kind, _ in self.lines], ["STATE", "PROGRESS", "DONE"])
|
||||
self.assertEqual(json.loads(self.lines[-1][1]), {"install_dir": "Z:" + folder, "exe": "WarcraftRumble.exe", "version": "16.1.2.119725"})
|
||||
|
||||
def test_an_install_on_another_volume_is_handed_over_by_its_drive_once_the_prefix_is_stopped(self):
|
||||
self.install()
|
||||
card = self.tmp / "card"
|
||||
folder = str(card / "Games/Battle.net/Warcraft Rumble")
|
||||
self.files = {".json": json.dumps({"progress": 1.0, "download_complete": True, "state": 1004}),
|
||||
".game": json.dumps({"installed": True, "install_dir": "D:/Games/Battle.net/Warcraft Rumble", "local_version": "1",
|
||||
"binaries": {"game": {"relative_path": "WarcraftRumble.exe"}}})}
|
||||
self.states = [[(7, self.AGENT)]]
|
||||
events = []
|
||||
real_map = BNET["map_drive"]
|
||||
|
||||
def acquire(folder=None):
|
||||
events.append("lock")
|
||||
return self.lock
|
||||
|
||||
def stop(pfx):
|
||||
events.append(("stop", not self.lock.closed))
|
||||
self.states = [[]]
|
||||
return True
|
||||
|
||||
def map_drive(root, volume):
|
||||
events.append(("map", not self.lock.closed))
|
||||
return real_map(root, volume)
|
||||
|
||||
with mock.patch.dict(BNET, {"volume_root": lambda path: str(card), "stop_leftovers": stop, "map_drive": map_drive,
|
||||
"acquire": acquire}):
|
||||
code = BNET["agent_job"](self.root, "install", "gryphon", "gryphon", folder, "enUS", "USA", "US", poll=0)
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(events, ["lock", ("stop", True), ("map", True)])
|
||||
self.assertTrue(self.lock.closed)
|
||||
cmd = self.started[0]
|
||||
self.assertEqual(cmd[cmd.index("--") + 6], "D:\\Games\\Battle.net\\Warcraft Rumble")
|
||||
self.assertEqual(os.readlink(os.path.join(BNET["dosdevices"](self.root), "d:")), str(card))
|
||||
|
||||
def test_an_agent_error_is_reported_with_its_code(self):
|
||||
self.install()
|
||||
self.files = {".json": json.dumps({"error": 2421, "progress": 0.0})}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
USERNS = shutil.which("unshare") is not None and subprocess.run(["unshare", "-Urm", "true"], capture_output=True).returncode == 0
|
||||
|
||||
FASTPATH = Path(__file__).resolve().parents[1] / "proot/fastpath/fastpath.c"
|
||||
|
||||
PROGRAM = r"""
|
||||
#include "FASTPATH"
|
||||
#include <sys/mount.h>
|
||||
|
||||
static long host_sys(long nr, long a, long b, long c, long d, long e, long f) {
|
||||
long r = syscall(nr, a, b, c, d, e, f);
|
||||
return r < 0 ? -errno : r;
|
||||
}
|
||||
|
||||
static void show(long r) {
|
||||
if (r == FP_SLOW) puts("SLOW");
|
||||
else if (r < 0) printf("E%ld\n", -r);
|
||||
else puts("ok");
|
||||
}
|
||||
|
||||
static int high_fds(void) {
|
||||
int n = 0;
|
||||
for (int fd = DIR_FD_FLOOR; fd < DIR_FD_FLOOR + 4 * DIRS; fd++)
|
||||
if (fcntl(fd, F_GETFD) >= 0) n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
static char hosts[MAX_BINDS][PATH_MAX], guests[MAX_BINDS][512];
|
||||
static int taken[DIRS];
|
||||
int ntaken = 0;
|
||||
fp_sys = host_sys;
|
||||
snprintf(root, sizeof root, "%s", argv[1]);
|
||||
rootlen = strlen(root);
|
||||
int i = 2;
|
||||
for (; i + 1 < argc && strcmp(argv[i], "--"); i += 2) {
|
||||
struct bind *bd = &binds[nbinds];
|
||||
bd->host = hosts[nbinds];
|
||||
bd->guest = guests[nbinds];
|
||||
snprintf(bd->host, PATH_MAX, "%s", argv[i]);
|
||||
snprintf(bd->guest, sizeof guests[0], "%s", argv[i + 1]);
|
||||
bd->hlen = strlen(bd->host);
|
||||
bd->glen = strlen(bd->guest);
|
||||
nbinds++;
|
||||
}
|
||||
pthread_once(&init_once, fp_init);
|
||||
fp_on = 1;
|
||||
for (i++; i < argc; i++) {
|
||||
const char *op = argv[i];
|
||||
if (!strcmp(op, "fuse")) {
|
||||
for (int b = 0; b < nbinds; b++) binds[b].fuse = 1;
|
||||
} else if (!strcmp(op, "touch")) {
|
||||
long fd = fp_open(AT_FDCWD, argv[++i], O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
|
||||
if (fd >= 0) close((int)fd);
|
||||
show(fd);
|
||||
} else if (!strcmp(op, "stat")) {
|
||||
struct stat st;
|
||||
show(fp_stat(AT_FDCWD, argv[++i], AT_SYMLINK_NOFOLLOW, &st));
|
||||
} else if (!strcmp(op, "mkdir")) {
|
||||
show(fp_mkdir(AT_FDCWD, argv[++i], 0755));
|
||||
} else if (!strcmp(op, "mv")) {
|
||||
show(fp_rename(AT_FDCWD, argv[i + 1], AT_FDCWD, argv[i + 2], 0));
|
||||
i += 2;
|
||||
} else if (!strcmp(op, "rm")) {
|
||||
show(fp_unlink(AT_FDCWD, argv[++i], 0));
|
||||
} else if (!strcmp(op, "host-mv")) {
|
||||
show(host_sys(SYS_renameat, AT_FDCWD, (long)argv[i + 1], AT_FDCWD, (long)argv[i + 2], 0, 0));
|
||||
i += 2;
|
||||
} else if (!strcmp(op, "host-rmdir")) {
|
||||
show(host_sys(SYS_unlinkat, AT_FDCWD, (long)argv[++i], AT_REMOVEDIR, 0, 0, 0));
|
||||
} else if (!strcmp(op, "host-mkdir")) {
|
||||
show(host_sys(SYS_mkdirat, AT_FDCWD, (long)argv[++i], 0755, 0, 0, 0));
|
||||
} else if (!strcmp(op, "clobber")) {
|
||||
long null = host_sys(SYS_openat, AT_FDCWD, (long)"/dev/null", O_RDONLY, 0, 0, 0);
|
||||
for (int fd = DIR_FD_FLOOR; fd < DIR_FD_FLOOR + DIRS; fd++) host_sys(SYS_dup3, null, fd, 0, 0, 0, 0);
|
||||
host_sys(SYS_close, null, 0, 0, 0, 0, 0);
|
||||
puts("ok");
|
||||
} else if (!strcmp(op, "first-fd")) {
|
||||
char link[40], out[PATH_MAX];
|
||||
snprintf(link, sizeof link, "/proc/self/fd/%d", DIR_FD_FLOOR);
|
||||
long n = host_sys(SYS_readlinkat, AT_FDCWD, (long)link, (long)out, sizeof out - 1, 0, 0);
|
||||
out[n > 0 ? n : 0] = 0;
|
||||
puts(out);
|
||||
} else if (!strcmp(op, "fds")) {
|
||||
printf("%d\n", high_fds());
|
||||
} else if (!strcmp(op, "ttl")) {
|
||||
ttl_ns = atoll(argv[++i]) * 1000000LL;
|
||||
} else if (!strcmp(op, "sleep")) {
|
||||
usleep(atoi(argv[++i]) * 1000);
|
||||
} else if (!strcmp(op, "chmod")) {
|
||||
show(fp_chmod(AT_FDCWD, argv[i + 1], strtol(argv[i + 2], NULL, 8), 0));
|
||||
i += 2;
|
||||
} else if (!strcmp(op, "host-mount")) {
|
||||
show(mount("tmpfs", argv[++i], "tmpfs", 0, NULL) == 0 ? 0 : -errno);
|
||||
} else if (!strcmp(op, "take-over")) {
|
||||
for (int fd = DIR_FD_FLOOR; fd < DIR_FD_FLOOR + DIRS; fd++) {
|
||||
char link[40], out[PATH_MAX];
|
||||
snprintf(link, sizeof link, "/proc/self/fd/%d", fd);
|
||||
long n = host_sys(SYS_readlinkat, AT_FDCWD, (long)link, (long)out, sizeof out - 1, 0, 0);
|
||||
if (n <= 0) continue;
|
||||
out[n] = 0;
|
||||
long mine = host_sys(SYS_openat, AT_FDCWD, (long)out, O_RDONLY | O_DIRECTORY, 0, 0, 0);
|
||||
host_sys(SYS_dup3, mine, fd, 0, 0, 0, 0);
|
||||
host_sys(SYS_close, mine, 0, 0, 0, 0, 0);
|
||||
taken[ntaken++] = fd;
|
||||
}
|
||||
puts("ok");
|
||||
} else if (!strcmp(op, "taken")) {
|
||||
int open_fds = 0;
|
||||
for (int t = 0; t < ntaken; t++)
|
||||
if (lseek(taken[t], 0, SEEK_CUR) == 0) open_fds++;
|
||||
printf("%d/%d\n", open_fds, ntaken);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class FastPathFuseDirsTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if shutil.which("gcc") is None:
|
||||
raise unittest.SkipTest("gcc is not available")
|
||||
cls.build = tempfile.TemporaryDirectory()
|
||||
source = Path(cls.build.name) / "fuse_dirs.c"
|
||||
source.write_text(PROGRAM.replace("FASTPATH", str(FASTPATH)))
|
||||
cls.program = Path(cls.build.name) / "fuse_dirs"
|
||||
subprocess.run(["gcc", "-O1", "-Wall", "-Wextra", "-Werror", "-Wno-format-truncation", "-pthread", "-o", str(cls.program), str(source), "-ldl"], check=True)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.build.cleanup()
|
||||
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
base = Path(self.temp.name)
|
||||
self.root = base / "root"
|
||||
(self.root / "mnt").mkdir(parents=True)
|
||||
self.card = base / "card"
|
||||
(self.card / "Games/steamapps/common/Game/Data").mkdir(parents=True)
|
||||
|
||||
def ask(self, *ops, wrap=()):
|
||||
argv = [*wrap, str(self.program), str(self.root), str(self.card), "/mnt/card", "--", *ops]
|
||||
return subprocess.run(argv, capture_output=True, text=True, timeout=20, check=True).stdout.split()
|
||||
|
||||
def test_files_deep_in_a_fuse_library_are_created_renamed_and_removed(self):
|
||||
data = "/mnt/card/Games/steamapps/common/Game/Data"
|
||||
out = self.ask("fuse", "touch", f"{data}/a.tmp", "mv", f"{data}/a.tmp", f"{data}/a.idx",
|
||||
"stat", f"{data}/a.idx", "stat", f"{data}/a.tmp", "rm", f"{data}/a.idx",
|
||||
"stat", f"{data}/a.idx", "fds")
|
||||
self.assertEqual(["ok", "ok", "ok", "E2", "ok", "E2"], out[:-1])
|
||||
self.assertGreater(int(out[-1]), 0)
|
||||
self.assertEqual([], list((self.card / "Games/steamapps/common/Game/Data").iterdir()))
|
||||
|
||||
def test_a_folder_renamed_behind_the_cache_is_not_reused(self):
|
||||
game = self.card / "Games/steamapps/common/Game"
|
||||
(game / "Data/keep").write_text("x")
|
||||
out = self.ask("fuse", "stat", "/mnt/card/Games/steamapps/common/Game/Data/keep",
|
||||
"host-mv", str(game), str(game.parent / "Moved"),
|
||||
"stat", "/mnt/card/Games/steamapps/common/Game/Data/keep",
|
||||
"stat", "/mnt/card/Games/steamapps/common/Moved/Data/keep")
|
||||
self.assertEqual(["ok", "ok", "E2", "ok"], out)
|
||||
|
||||
def test_a_folder_deleted_and_made_again_is_looked_up_fresh(self):
|
||||
data = self.card / "Games/steamapps/common/Game/Data"
|
||||
out = self.ask("fuse", "touch", "/mnt/card/Games/steamapps/common/Game/Data/old",
|
||||
"rm", "/mnt/card/Games/steamapps/common/Game/Data/old",
|
||||
"host-rmdir", str(data), "host-mkdir", str(data),
|
||||
"touch", "/mnt/card/Games/steamapps/common/Game/Data/new")
|
||||
self.assertEqual(["ok"] * 5, out)
|
||||
self.assertEqual(["new"], [p.name for p in data.iterdir()])
|
||||
|
||||
def test_folders_deleted_and_made_again_many_times_keep_descriptors_bounded(self):
|
||||
data = self.card / "Games/steamapps/common/Game/Data"
|
||||
ops = ["fuse"]
|
||||
for _ in range(200):
|
||||
ops += ["touch", "/mnt/card/Games/steamapps/common/Game/Data/x",
|
||||
"rm", "/mnt/card/Games/steamapps/common/Game/Data/x",
|
||||
"host-rmdir", str(data), "host-mkdir", str(data)]
|
||||
out = self.ask(*ops, "fds")
|
||||
self.assertEqual(["ok"] * 800, out[:-1])
|
||||
self.assertLessEqual(int(out[-1]), 64)
|
||||
|
||||
def test_descriptors_the_program_takes_over_are_left_alone(self):
|
||||
data = "/mnt/card/Games/steamapps/common/Game/Data"
|
||||
out = self.ask("fuse", "touch", f"{data}/a", "clobber", "touch", f"{data}/b",
|
||||
"stat", f"{data}/a", "first-fd")
|
||||
self.assertEqual(["ok", "ok", "ok", "ok", "/dev/null"], out)
|
||||
self.assertEqual({"a", "b"}, {p.name for p in (self.card / "Games/steamapps/common/Game/Data").iterdir()})
|
||||
|
||||
def test_a_folder_the_program_opened_itself_stays_open_when_the_cache_moves_on(self):
|
||||
data = self.card / "Games/steamapps/common/Game/Data"
|
||||
ops = ["fuse", "touch", "/mnt/card/Games/steamapps/common/Game/Data/a", "take-over"]
|
||||
for n in range(200):
|
||||
(data / f"d{n}").mkdir()
|
||||
ops += ["touch", f"/mnt/card/Games/steamapps/common/Game/Data/d{n}/x"]
|
||||
out = self.ask(*ops, "taken")
|
||||
self.assertEqual(["ok"] * 202, out[:-1])
|
||||
opened, total = map(int, out[-1].split("/"))
|
||||
self.assertGreater(total, 0)
|
||||
self.assertEqual(total, opened)
|
||||
self.assertEqual(200, len(list(data.glob("d*/x"))))
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root passes folder permissions")
|
||||
def test_a_parent_folder_closed_by_the_program_stops_cached_access_at_once(self):
|
||||
game = self.card / "Games/steamapps/common/Game"
|
||||
(game / "Data/keep").write_text("x")
|
||||
self.addCleanup(os.chmod, game, 0o755)
|
||||
out = self.ask("fuse", "stat", "/mnt/card/Games/steamapps/common/Game/Data/keep",
|
||||
"chmod", "/mnt/card/Games/steamapps/common/Game", "000",
|
||||
"stat", "/mnt/card/Games/steamapps/common/Game/Data/keep",
|
||||
"touch", "/mnt/card/Games/steamapps/common/Game/Data/new")
|
||||
self.assertEqual(["ok", "ok"], out[:2])
|
||||
self.assertNotIn("ok", out[2:])
|
||||
os.chmod(game, 0o755)
|
||||
self.assertEqual(["keep"], [p.name for p in (game / "Data").iterdir()])
|
||||
|
||||
@unittest.skipUnless(USERNS, "mount namespaces are not available")
|
||||
def test_a_mount_placed_over_a_cached_folder_receives_later_writes(self):
|
||||
data = self.card / "Games/steamapps/common/Game/Data"
|
||||
out = self.ask("fuse", "ttl", "1", "touch", "/mnt/card/Games/steamapps/common/Game/Data/under",
|
||||
"host-mount", str(data), "sleep", "20",
|
||||
"touch", "/mnt/card/Games/steamapps/common/Game/Data/over",
|
||||
"stat", "/mnt/card/Games/steamapps/common/Game/Data/under", wrap=("unshare", "-Urm"))
|
||||
self.assertEqual(["ok", "ok", "ok", "E2"], out)
|
||||
self.assertEqual(["under"], [p.name for p in data.iterdir()])
|
||||
|
||||
def test_other_filesystems_keep_absolute_paths_and_open_no_folders(self):
|
||||
data = "/mnt/card/Games/steamapps/common/Game/Data"
|
||||
out = self.ask("touch", f"{data}/a", "mv", f"{data}/a", f"{data}/b", "rm", f"{data}/b", "fds")
|
||||
self.assertEqual(["ok", "ok", "ok", "0"], out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user