diff --git a/core/src/main/java/com/threerings/getdown/data/Application.java b/core/src/main/java/com/threerings/getdown/data/Application.java index 1a4729c..3719d45 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -431,7 +431,7 @@ public class Application try { URL remote = new URL(createVAppBase(_targetVersion), encodePath(_javaLocation)); return new Resource(vmfile, remote, getLocalPath(vmfile), - EnumSet.of(Resource.Attr.UNPACK)); + EnumSet.of(Resource.Attr.UNPACK, Resource.Attr.CLEAN)); } catch (Exception e) { log.warning("Failed to create VM resource", "vmfile", vmfile, "appbase", _appbase, "tvers", _targetVersion, "javaloc", _javaLocation, "error", e); diff --git a/core/src/main/java/com/threerings/getdown/data/Resource.java b/core/src/main/java/com/threerings/getdown/data/Resource.java index a7601ca..412ce93 100644 --- a/core/src/main/java/com/threerings/getdown/data/Resource.java +++ b/core/src/main/java/com/threerings/getdown/data/Resource.java @@ -31,6 +31,9 @@ public class Resource implements Comparable public static enum Attr { /** Indicates that the resource should be unpacked. */ UNPACK, + /** If present, when unpacking a resource, any directories created by the newly + * unpacked resource will first be cleared of files before unpacking. */ + CLEAN, /** Indicates that the resource should be marked executable. */ EXEC }; @@ -254,21 +257,20 @@ public class Resource implements Comparable /** * Installs the {@code getLocalNew} version of this resource to {@code getLocal}. */ - public void install (boolean cleanExistingDirs) throws IOException { + public void install () throws IOException { File source = getLocalNew(), dest = getLocal(); log.info("- " + source); if (!FileUtil.renameTo(source, dest)) { throw new IOException("Failed to rename " + source + " to " + dest); } - applyAttrs(cleanExistingDirs); + applyAttrs(); markAsValid(); } - /** * Unpacks this resource file into the directory that contains it. */ - public void unpack (boolean cleanExistingDirs) throws IOException + public void unpack () throws IOException { // sanity check if (!_isJar && !_isPacked200Jar) { @@ -276,35 +278,26 @@ public class Resource implements Comparable } if (_isJar) { try (JarFile jar = new JarFile(_local)) { - FileUtil.unpackJar(jar, _unpacked, cleanExistingDirs); + FileUtil.unpackJar(jar, _unpacked, _attrs.contains(Attr.CLEAN)); } } else { FileUtil.unpackPacked200Jar(_local, _unpacked); } } - - public void unpack () throws IOException - { - unpack(false); - } /** * Applies this resources special attributes: unpacks this resource if needed, marks it as * executable if needed. */ - public void applyAttrs (boolean cleanExistingDirs) throws IOException { + public void applyAttrs () throws IOException { if (shouldUnpack()) { - unpack(cleanExistingDirs); + unpack(); } if (_attrs.contains(Attr.EXEC)) { FileUtil.makeExecutable(_local); } } - public void applyAttrs () throws IOException { - applyAttrs(false); - } - /** * Wipes this resource file along with any "validated" marker file that may be associated with * it. diff --git a/core/src/main/java/com/threerings/getdown/util/FileUtil.java b/core/src/main/java/com/threerings/getdown/util/FileUtil.java index 0008a4f..378f701 100644 --- a/core/src/main/java/com/threerings/getdown/util/FileUtil.java +++ b/core/src/main/java/com/threerings/getdown/util/FileUtil.java @@ -93,26 +93,29 @@ public class FileUtil /** * Unpacks the specified jar file into the specified target directory. + * @param cleanExistingDirs if true, all files in all directories contained in {@code jar} will + * be deleted prior to unpacking the jar. */ - public static void unpackJar (JarFile jar, File target, boolean cleanExistingDirs) throws IOException + public static void unpackJar (JarFile jar, File target, boolean cleanExistingDirs) + throws IOException { - Enumeration entries = jar.entries(); - if (cleanExistingDirs) - { - while (entries.hasMoreElements()) { - JarEntry entry = (JarEntry) entries.nextElement(); - if (entry.isDirectory()) { - File efile = new File(target, entry.getName()); - if (efile.exists()) { - for (File f : efile.listFiles()) { - if (!f.isDirectory()) - f.delete(); - } - } - } - } + if (cleanExistingDirs) { + Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) { + JarEntry entry = (JarEntry)entries.nextElement(); + if (entry.isDirectory()) { + File efile = new File(target, entry.getName()); + if (efile.exists()) { + for (File f : efile.listFiles()) { + if (!f.isDirectory()) + f.delete(); + } + } + } + } } - entries = jar.entries(); + + Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry)entries.nextElement(); File efile = new File(target, entry.getName()); diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java index a970c01..17368b1 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -116,7 +116,7 @@ public abstract class Getdown extends Thread } else if (_readyToInstall) { log.info("Installing " + _toInstallResources.size() + " downloaded resources:"); for (Resource resource : _toInstallResources) { - resource.install(false); + resource.install(); } _toInstallResources.clear(); _readyToInstall = false; @@ -589,7 +589,7 @@ public abstract class Getdown extends Thread reportTrackingEvent("jvm_unpack", -1); updateStatus("m.unpacking_java"); - vmjar.install(true); + vmjar.install(); // these only run on non-Windows platforms, so we use Unix file separators String localJavaDir = LaunchUtil.LOCAL_JAVA_DIR + "/";