Skip to content

Commit

Permalink
Merge pull request #170 from pb00068/unPackFix
Browse files Browse the repository at this point in the history
Fix for #112, installing a newer JVM leaves parts of the old JVM
  • Loading branch information
samskivert committed Nov 30, 2018
2 parents ac876a3 + dd9c83a commit 37b6575
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
22 changes: 16 additions & 6 deletions core/src/main/java/com/threerings/getdown/data/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,47 +254,57 @@ public void clearMarker ()
/**
* Installs the {@code getLocalNew} version of this resource to {@code getLocal}.
*/
public void install () throws IOException {
public void install (boolean cleanExistingDirs) 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();
applyAttrs(cleanExistingDirs);
markAsValid();
}


/**
* Unpacks this resource file into the directory that contains it.
*/
public void unpack () throws IOException
public void unpack (boolean cleanExistingDirs) throws IOException
{
// sanity check
if (!_isJar && !_isPacked200Jar) {
throw new IOException("Requested to unpack non-jar file '" + _local + "'.");
}
if (_isJar) {
try (JarFile jar = new JarFile(_local)) {
FileUtil.unpackJar(jar, _unpacked);
FileUtil.unpackJar(jar, _unpacked, cleanExistingDirs);
}
} 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 () throws IOException {
public void applyAttrs (boolean cleanExistingDirs) throws IOException {
if (shouldUnpack()) {
unpack();
unpack(cleanExistingDirs);
}
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.
Expand Down
18 changes: 17 additions & 1 deletion core/src/main/java/com/threerings/getdown/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,25 @@ public static List<String> readLines (Reader in)
/**
* Unpacks the specified jar file into the specified target directory.
*/
public static void unpackJar (JarFile jar, File target) 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();
}
}
}
}
}
entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry)entries.nextElement();
File efile = new File(target, entry.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void install () throws IOException
} else if (_readyToInstall) {
log.info("Installing " + _toInstallResources.size() + " downloaded resources:");
for (Resource resource : _toInstallResources) {
resource.install();
resource.install(false);
}
_toInstallResources.clear();
_readyToInstall = false;
Expand Down Expand Up @@ -589,7 +589,7 @@ protected void updateJava ()
reportTrackingEvent("jvm_unpack", -1);

updateStatus("m.unpacking_java");
vmjar.install();
vmjar.install(true);

// these only run on non-Windows platforms, so we use Unix file separators
String localJavaDir = LaunchUtil.LOCAL_JAVA_DIR + "/";
Expand Down

0 comments on commit 37b6575

Please sign in to comment.