Recursive file deletion is broken on Windows
octylFractal opened this issue ยท 1 comments
Versions
WorldEdit version: 7.2.0-beta-2
Platform version: 1.16.1, git-Paper-74
Describe the bug
On Windows, regen "fails" due to being unable to cleanup the temporary world gen.
To Reproduce
- Use Windows
//regen
Expected behavior
No errors should be propagated out.
Additional context
There's a solution that Gradle has for this. I'll be looking at that and seeing if we can port it.
Edit: stacktrace:
[10:14:11] [Server thread/WARN]: Regeneration via adapter failed.
java.lang.IllegalStateException: Regen failed.
at com.sk89q.worldedit.bukkit.adapter.impl.Spigot_v1_16_R1.regenerate(Spigot_v1_16_R1.java:578) ~[?:?]
at com.sk89q.worldedit.bukkit.BukkitWorld.regenerate(BukkitWorld.java:219) ~[?:?]
at com.sk89q.worldedit.command.RegionCommands.regenerate(RegionCommands.java:424) ~[?:?]
at com.sk89q.worldedit.command.RegionCommandsRegistration.cmd$_regen(RegionCommandsRegistration.java:584) ~[?:?]
at org.enginehub.piston.CommandManager.execute(CommandManager.java:157) ~[?:?]
at com.sk89q.worldedit.extension.platform.PlatformCommandManager.handleCommand(PlatformCommandManager.java:491) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_251]
at com.sk89q.worldedit.util.eventbus.MethodEventHandler.dispatch(MethodEventHandler.java:58) ~[?:?]
at com.sk89q.worldedit.util.eventbus.EventHandler.handleEvent(EventHandler.java:73) ~[?:?]
at com.sk89q.worldedit.util.eventbus.EventBus.dispatch(EventBus.java:193) ~[?:?]
at com.sk89q.worldedit.util.eventbus.EventBus.post(EventBus.java:181) ~[?:?]
at com.sk89q.worldedit.bukkit.WorldEditPlugin.onCommand(WorldEditPlugin.java:350) ~[?:?]
at com.sk89q.bukkit.util.DynamicPluginCommand.execute(DynamicPluginCommand.java:55) ~[?:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.16.1.jar:git-Paper-74]
at org.bukkit.craftbukkit.v1_16_R1.CraftServer.dispatchCommand(CraftServer.java:794) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.PlayerConnection.handleCommand(PlayerConnection.java:1908) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.PlayerConnection.a(PlayerConnection.java:1719) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:23) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.TickTask.run(SourceFile:18) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.MinecraftServer.aZ(MinecraftServer.java:1136) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.MinecraftServer.executeNext(MinecraftServer.java:1129) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.IAsyncTaskHandler.executeAll(IAsyncTaskHandler.java:95) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.MinecraftServer.a(MinecraftServer.java:1259) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.MinecraftServer.v(MinecraftServer.java:1000) ~[patched_1.16.1.jar:git-Paper-74]
at net.minecraft.server.v1_16_R1.MinecraftServer.lambda$a$0(MinecraftServer.java:177) ~[patched_1.16.1.jar:git-Paper-74]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
Caused by: java.io.IOException: Unable to delete directory C:\Users\Owner\AppData\Local\Temp\WorldEditWorldGen3103927293674779749\worldeditregentempworld.
at org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1581) ~[patched_1.16.1.jar:git-Paper-74]
at org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:2372) ~[patched_1.16.1.jar:git-Paper-74]
at org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1679) ~[patched_1.16.1.jar:git-Paper-74]
at org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1575) ~[patched_1.16.1.jar:git-Paper-74]
at com.sk89q.worldedit.bukkit.adapter.impl.Spigot_v1_16_R1.doRegen(Spigot_v1_16_R1.java:643) ~[?:?]
at com.sk89q.worldedit.bukkit.adapter.impl.Spigot_v1_16_R1.regenerate(Spigot_v1_16_R1.java:576) ~[?:?]
... 33 more
Leaving this here for later:
private boolean tryHardToDelete(File file) {
if (deleteFile(file)) {
return true;
}
// This is copied from Ant (see org.apache.tools.ant.util.FileUtils.tryHardToDelete).
// It mentions that there is a bug in the Windows JDK implementations that this is a valid
// workaround for. I've been unable to find a definitive reference to this bug.
// The thinking is that if this is good enough for Ant, it's good enough for us.
if (runGcOnFailedDelete) {
System.gc();
}
try {
Thread.sleep(DELETE_RETRY_SLEEP_MILLIS);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
return deleteFile(file);
}