From ed24b53783f84be1da3351c4745a75860959482e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 5 Apr 2015 19:06:55 +0200 Subject: [PATCH] Cleaning up old native libs when not using the tmp dir. --- .../scala/li/cil/oc/util/LuaStateFactory.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/util/LuaStateFactory.scala b/src/main/scala/li/cil/oc/util/LuaStateFactory.scala index 3bb7ef11b..d05a218a0 100644 --- a/src/main/scala/li/cil/oc/util/LuaStateFactory.scala +++ b/src/main/scala/li/cil/oc/util/LuaStateFactory.scala @@ -4,8 +4,10 @@ import java.io.File import java.io.FileInputStream import java.io.FileOutputStream import java.nio.channels.Channels +import java.util.regex.Pattern import com.google.common.base.Strings +import com.google.common.io.PatternFilenameFilter import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.server.machine.Machine @@ -105,9 +107,21 @@ object LuaStateFactory { else if (path.endsWith("/") || path.endsWith("\\")) path else path + "/" } - else "" + else "./" val tmpLibFile = new File(tmpBasePath + tmpLibName) + // Clean up old library files when not in tmp dir. + if (!Settings.get.nativeInTmpDir) { + val libDir = new File(tmpBasePath) + if (libDir.isDirectory) { + for (file <- libDir.listFiles(new PatternFilenameFilter("^" + Pattern.quote("OpenComputersMod-") + ".*" + Pattern.quote("-" + libraryName) + "$"))) { + if (file.compareTo(tmpLibFile) != 0) { + file.delete() + } + } + } + } + // If the file, already exists, make sure it's the same we need, if it's // not disable use of the natives. if (tmpLibFile.exists()) {