From 4c87d98aaad5a0de0d8e71d28cef6f420ecabf62 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 29 Sep 2021 11:34:58 +0200 Subject: [PATCH] Fix Mod unpack folder move (#5346) * Fix Mod unpack folder move * Fix Mod unpack folder move - comment --- core/src/com/unciv/ui/worldscreen/mainmenu/GitHub.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/GitHub.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/GitHub.kt index dffd7845e2..7e70739846 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/GitHub.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/GitHub.kt @@ -107,10 +107,18 @@ object Github { return finalDestination } - + private fun FileHandle.renameOrMove(dest: FileHandle) { // Gdx tries a java rename for Absolute and External, but NOT for Local - rectify that - if (type() == Files.FileType.Local && file().renameTo(dest.file())) return + if (type() == Files.FileType.Local) { + // See #5346: renameTo 'unpacks' a source folder if the destination exists and is an + // empty folder, dropping the name of the source entirely. + // Safer to ask for a move to the not-yet-existing full resulting path instead. + if (isDirectory) + if (file().renameTo(dest.child(name()).file())) return + else + if (file().renameTo(dest.file())) return + } moveTo(dest) }