mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
fix(native): relink absolute symlinks again after any proot run (#2934)
* fix(native): relink absolute symlinks again after any proot run * fix(native): keep links into shared storage and relink rootfs trees made since the last walk A link into /root/Storage (the Downloads and Documents links) points at a mount, which a relative link would miss; it keeps its guest path. The stamp version moves on so rootfs trees that already ran a proot session after the last walk are walked once more. * fix(native): leave the relink stamp unwritten while a proot run is alive --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
3 files changed
+101
-6
No files matched your search
@@ -14,6 +14,8 @@ import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.Implementation
|
||||
import org.robolectric.annotation.Implements
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33], manifest = Config.NONE, application = Application::class, shadows = [LinuxRuntimeRootPrefixTest.Uname::class])
|
||||
@@ -44,6 +46,82 @@ class LinuxRuntimeRootPrefixTest {
|
||||
assertEquals(LinuxRuntime.prootPrefix(context, root, "/root"), cmd.dropLast(guest.size))
|
||||
}
|
||||
|
||||
@Test fun aLinkProotMadeAfterTheNativeRelinkIsMadeRelativeAtTheNextNativeStart() {
|
||||
val home = File(root, "root/.steam").apply { mkdirs() }
|
||||
File(root, "root/.local/share/Steam/logs").mkdirs()
|
||||
val steam = File(home, "steam").toPath()
|
||||
val card = File(home, "card").toPath()
|
||||
Files.createSymbolicLink(card, Paths.get("/storage/emulated/0"))
|
||||
NativeGuest.relinkAbsoluteSymlinks(context, root)
|
||||
Files.createSymbolicLink(steam, Paths.get("/root/.local/share/Steam"))
|
||||
assertEquals(0, NativeGuest.relinkAbsoluteSymlinks(context, root))
|
||||
assertTrue(Files.readSymbolicLink(steam).isAbsolute)
|
||||
|
||||
LinuxRuntime.prootPrefix(context, root, "/root")
|
||||
|
||||
assertEquals(1, NativeGuest.relinkAbsoluteSymlinks(context, root))
|
||||
assertEquals(Paths.get("../.local/share/Steam"), Files.readSymbolicLink(steam))
|
||||
assertTrue(File(home, "steam/logs").isDirectory)
|
||||
assertEquals(Paths.get("/storage/emulated/0"), Files.readSymbolicLink(card))
|
||||
}
|
||||
|
||||
@Test fun linksIntoSharedStorageKeepTheirGuestPath() {
|
||||
val home = File(root, "root").apply { mkdirs() }
|
||||
File(home, "Storage/Download").mkdirs()
|
||||
File(root, "root/.local/share/Steam").mkdirs()
|
||||
val downloads = File(home, "Downloads").toPath()
|
||||
val storage = File(home, "Storage").toPath()
|
||||
val steam = File(home, "steam").toPath()
|
||||
Files.createSymbolicLink(downloads, Paths.get("/root/Storage/Download"))
|
||||
Files.createSymbolicLink(File(home, "share").toPath(), Paths.get("/root/Storage"))
|
||||
Files.createSymbolicLink(steam, Paths.get("/root/.local/share/Steam"))
|
||||
Files.createSymbolicLink(File(home, "StorageX").toPath(), Paths.get("/root/StorageX"))
|
||||
|
||||
assertEquals(2, NativeGuest.relinkAbsoluteSymlinks(context, root))
|
||||
|
||||
assertEquals(Paths.get("/root/Storage/Download"), Files.readSymbolicLink(downloads))
|
||||
assertEquals(Paths.get("/root/Storage"), Files.readSymbolicLink(File(home, "share").toPath()))
|
||||
assertEquals(Paths.get(".local/share/Steam"), Files.readSymbolicLink(steam))
|
||||
assertEquals(Paths.get("StorageX"), Files.readSymbolicLink(File(home, "StorageX").toPath()))
|
||||
assertTrue(Files.isDirectory(storage))
|
||||
}
|
||||
|
||||
@Test fun aWalkDuringALiveProotRunLeavesTheNextNativeStartToWalkAgain() {
|
||||
val home = File(root, "root").apply { mkdirs() }
|
||||
File(root, "root/.local/share/Steam").mkdirs()
|
||||
val proot = LinuxRuntime.prootBinary(context).path
|
||||
LinuxRuntime.prootPrefix(context, root, "/root")
|
||||
NativeGuest.relinkAbsoluteSymlinks(context, root) { sequenceOf(listOf("/system/bin/linker64", proot, "--kill-on-exit")) }
|
||||
val steam = File(home, "steam").toPath()
|
||||
Files.createSymbolicLink(steam, Paths.get("/root/.local/share/Steam"))
|
||||
|
||||
assertEquals(1, NativeGuest.relinkAbsoluteSymlinks(context, root) { emptySequence() })
|
||||
assertEquals(Paths.get(".local/share/Steam"), Files.readSymbolicLink(steam))
|
||||
assertEquals(0, NativeGuest.relinkAbsoluteSymlinks(context, root) { emptySequence() })
|
||||
}
|
||||
|
||||
@Test fun onlyTheProotTracerCountsAsALiveProotRun() {
|
||||
val proot = "/data/app/x/lib/arm64/libproot.so"
|
||||
assertTrue(NativeGuest.prootRunning(proot, sequenceOf(listOf("/system/bin/linker64", proot, "-r", "/rootfs"))))
|
||||
assertTrue(NativeGuest.prootRunning(proot, sequenceOf(listOf(proot, "-r", "/rootfs"))))
|
||||
assertFalse(NativeGuest.prootRunning(proot, sequenceOf(listOf("/usr/bin/bash", "-c", proot))))
|
||||
assertFalse(NativeGuest.prootRunning(proot, sequenceOf(listOf("$proot.old"), emptyList())))
|
||||
}
|
||||
|
||||
@Test fun packageLinksAFakeRootProotRunMadeAreRelinkedToo() {
|
||||
val bin = File(root, "usr/bin").apply { mkdirs() }
|
||||
File(root, "usr/share/tool").mkdirs()
|
||||
NativeGuest.relinkAbsoluteSymlinks(context, root)
|
||||
val tool = File(bin, "tool").toPath()
|
||||
Files.createSymbolicLink(tool, Paths.get("/usr/share/tool"))
|
||||
|
||||
LinuxRuntime.commandWithBinds(context, root, emptyList(), guest, true)
|
||||
|
||||
assertEquals(1, NativeGuest.relinkAbsoluteSymlinks(context, root))
|
||||
assertEquals(Paths.get("../share/tool"), Files.readSymbolicLink(tool))
|
||||
assertEquals(0, NativeGuest.relinkAbsoluteSymlinks(context, root))
|
||||
}
|
||||
|
||||
@Implements(Os::class)
|
||||
class Uname {
|
||||
companion object {
|
||||
|
||||
Reference in new issue
Block a user