From 431364b349e68cf20caf54e1f31b65e10e37b203 Mon Sep 17 00:00:00 2001
From: aldotms89 <119340049+aldotms89@users.noreply.github.com>
Date: Tue, 24 Nov 2026 22:41:11 -0600
Subject: [PATCH] Launcher: scan nested library folders
Search nested folders with a depth limit and directory symlink checks. Keep dump roots and excluded storage folders out of the descent. Exercise nested games, dumps and symlinks on the JVM.
---
.../java/dev/peanuts/ui/LibraryScanner.java | 4 ++--
.../main/java/dev/peanuts/ui/LibraryWalk.java | 11 +++++++++--
peanuts/tests/test_library_walk.py | 19 +++++++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/android/app/src/main/java/dev/peanuts/ui/LibraryScanner.java b/android/app/src/main/java/dev/peanuts/ui/LibraryScanner.java
index 752de0a6..10900769 100644
--- a/android/app/src/main/java/dev/peanuts/ui/LibraryScanner.java
+++ b/android/app/src/main/java/dev/peanuts/ui/LibraryScanner.java
@@ -30,7 +30,7 @@
import java.util.regex.Pattern;
/**
- * The library: every game in the roots (the game folder, then the update and DLC folders; each walked two levels deep) as *.nsp, *.xci, *.nsz, *.xcz, *.nup or a dump folder
+ * The library: every game in the roots (the game folder, then the update and DLC folders; including nested folders) as *.nsp, *.xci, *.nsz, *.xcz, *.nup or a dump folder
* (a version with exefs/main in a layout upstream's DumpLayout reads; mods left out: LibraryWalk), grouped by the base game's title ID, with a status per title.
*
* An NSP/XCI's titles come from the importer's probe (ImporterPort.probe: title id, application id, kind, version, name), kept in files/library-cache.json by
@@ -299,7 +299,7 @@ private static VersionInfo versionInfo(String titleId) {
// ---- The walk ----
- /** A root's dump folders and game files (LibraryWalk: two levels deep, mods left out) */
+ /** A root's dump folders and game files (LibraryWalk: recursive, mods left out) */
private void walk(File root, List out) {
LibraryWalk.walk(root, 0, new LibraryWalk.Sink() {
@Override public void dump(File d) { out.addAll(LibraryScanner.this.dump(d)); }
diff --git a/android/app/src/main/java/dev/peanuts/ui/LibraryWalk.java b/android/app/src/main/java/dev/peanuts/ui/LibraryWalk.java
index 3f956199..68206771 100644
--- a/android/app/src/main/java/dev/peanuts/ui/LibraryWalk.java
+++ b/android/app/src/main/java/dev/peanuts/ui/LibraryWalk.java
@@ -1,13 +1,14 @@
package dev.peanuts.ui;
import java.io.File;
+import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
/**
- * The library's walk over one root (LibraryScanner.scan): the dump folders and the files it finds, each root walked two levels deep. A dump folder holds the
+ * The library's walk over one root (LibraryScanner.scan): the dump folders and the files it finds, including nested folders. A dump folder holds the
* game's code in a layout upstream's DumpLayout reads ({@link #isDump}), and is not walked further. Mods are left out (issue #46): a mod for Eden or Atmosphere is
* a folder with exefs/ and romfs/ too, but its exefs/ holds patches and at most its own main.npdm and main, never the SDK's module sdk ({@link #wholeCode});
* and the walk does not go into a folder named mods, load (Eden's and yuzu's) or atmosphere below the root. Before, a mod with a main.npdm was taken as a dump
@@ -16,6 +17,10 @@
final class LibraryWalk {
private LibraryWalk() {}
+ // PEANUTS(upstream-candidate): bound recursive scans and skip large shared-storage trees at the root.
+ private static final int MAX_DEPTH = 12;
+ private static final Set STORAGE_FOLDERS = Set.of("Android", "DCIM");
+
/** Folders the walk does not go into: where emulators and Atmosphere keep mods */
private static final Set MOD_FOLDERS = new HashSet<>(Arrays.asList("mods", "load", "atmosphere"));
@@ -33,9 +38,11 @@ static void walk(File dir, int depth, Sink out) {
String n = f.getName();
if (n.startsWith(".") || n.endsWith("-work")) continue;
if (f.isDirectory()) {
+ // PEANUTS(upstream-candidate): keep nested collections searchable and skip directory symlink loops.
+ if (depth >= MAX_DEPTH || (depth == 0 && STORAGE_FOLDERS.contains(n)) || Files.isSymbolicLink(f.toPath())) continue;
if (MOD_FOLDERS.contains(n.toLowerCase(Locale.ROOT))) continue;
if (isDump(f)) out.dump(f);
- else if (depth < 2) walk(f, depth + 1, out);
+ else walk(f, depth + 1, out);
} else out.file(f);
}
}
diff --git a/peanuts/tests/test_library_walk.py b/peanuts/tests/test_library_walk.py
index 4ac2c192..cecfc855 100644
--- a/peanuts/tests/test_library_walk.py
+++ b/peanuts/tests/test_library_walk.py
@@ -141,6 +141,25 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.tmp.cleanup()
+ def test_nested_sources_and_depth_limit(self):
+ root = Path(self.tmp.name) / 'nested'
+ deep = 'Games/Publisher/Series/Title'
+ cap = '/'.join(['nested'] * 12)
+ files = [f'{deep}/Updates/game.nup', 'Games/Android/game.nsp', f'{cap}/game.xci']
+ dump = f'{deep}/Dump'
+ for rel in [*files, f'{dump}/base/exefs/main', f'{dump}/romfs/ignored.nsp',
+ 'Android/ignored.nsp', 'DCIM/ignored.nsp', f'{cap}/extra/ignored.nsp']:
+ f = root / rel
+ f.parent.mkdir(parents=True, exist_ok=True)
+ f.touch()
+ try:
+ (root / 'Games/back').symlink_to(root, target_is_directory=True)
+ except (NotImplementedError, OSError):
+ pass
+ out = subprocess.check_output(['java', '-cp', str(self.classes), 'dev.peanuts.ui.LibraryWalkTest', str(root)],
+ text=True, timeout=10)
+ self.assertCountEqual(out.splitlines(), [f'dump -1 {dump}', *(f'file {f}' for f in files)])
+
def test_mods_are_no_dumps(self):
self.assertEqual(sorted(self.dumps), DUMPS, 'only the real dump folders, each once, as the dump and not one of its versions')