Eliminate unchecked file.delete() return values, standardize the way files are deleted.
Ignoring a method's return value can cause the program to overlook unexpected states and conditions.
This commit is contained in:
@@ -706,7 +706,6 @@ public abstract class Getdown extends Thread
|
|||||||
// clean up the patch file
|
// clean up the patch file
|
||||||
if (!FileUtil.deleteHarder(prsrc.getLocal())) {
|
if (!FileUtil.deleteHarder(prsrc.getLocal())) {
|
||||||
log.warning("Failed to delete '" + prsrc + "'.");
|
log.warning("Failed to delete '" + prsrc + "'.");
|
||||||
prsrc.getLocal().deleteOnExit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
import com.samskivert.io.StreamUtil;
|
import com.samskivert.io.StreamUtil;
|
||||||
|
|
||||||
import com.threerings.getdown.data.Application;
|
import com.threerings.getdown.data.Application;
|
||||||
import com.threerings.getdown.data.Digest;
|
import com.threerings.getdown.data.Digest;
|
||||||
import com.threerings.getdown.data.Resource;
|
import com.threerings.getdown.data.Resource;
|
||||||
|
import com.threerings.getdown.util.FileUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates patch files between two particular revisions of an
|
* Generates patch files between two particular revisions of an
|
||||||
@@ -137,8 +137,8 @@ public class Differ
|
|||||||
File temp = rebuildJar(rsrc.getLocal());
|
File temp = rebuildJar(rsrc.getLocal());
|
||||||
jout.putNextEntry(new ZipEntry(rsrc.getPath() + Patcher.PATCH));
|
jout.putNextEntry(new ZipEntry(rsrc.getPath() + Patcher.PATCH));
|
||||||
jarDiff(otemp, temp, jout);
|
jarDiff(otemp, temp, jout);
|
||||||
otemp.delete();
|
FileUtil.deleteHarder(otemp);
|
||||||
temp.delete();
|
FileUtil.deleteHarder(temp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ public class Differ
|
|||||||
System.out.println("Created patch file: " + patch);
|
System.out.println("Created patch file: " + patch);
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
patch.delete();
|
FileUtil.deleteHarder(patch);
|
||||||
throw ioe;
|
throw ioe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class Patcher
|
|||||||
path = strip(path, DELETE);
|
path = strip(path, DELETE);
|
||||||
System.out.println("Removing " + path + "...");
|
System.out.println("Removing " + path + "...");
|
||||||
File target = new File(appdir, path);
|
File target = new File(appdir, path);
|
||||||
if (!target.delete()) {
|
if (!FileUtil.deleteHarder(target)) {
|
||||||
System.err.println("Failure deleting '" + target + "'.");
|
System.err.println("Failure deleting '" + target + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ public class Patcher
|
|||||||
JarDiffPatcher patcher = null;
|
JarDiffPatcher patcher = null;
|
||||||
|
|
||||||
// make sure no stale old target is lying around to mess us up
|
// make sure no stale old target is lying around to mess us up
|
||||||
otarget.delete();
|
FileUtil.deleteHarder(otarget);
|
||||||
|
|
||||||
// pipe the contents of the patch into a file
|
// pipe the contents of the patch into a file
|
||||||
try (InputStream in = file.getInputStream(entry);
|
try (InputStream in = file.getInputStream(entry);
|
||||||
@@ -170,12 +170,8 @@ public class Patcher
|
|||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
// clean up our temporary files
|
// clean up our temporary files
|
||||||
if (!patch.delete()) {
|
FileUtil.deleteHarder(patch);
|
||||||
patch.deleteOnExit();
|
FileUtil.deleteHarder(otarget);
|
||||||
}
|
|
||||||
if (!otarget.delete()) {
|
|
||||||
otarget.deleteOnExit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,14 +71,18 @@ public class FileUtil
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* "Tries harder" to delete {@code file} than just calling {@code delete} on it. Presently this
|
* "Tries harder" to delete {@code file} than just calling {@code delete} on it. Presently this
|
||||||
* just means "try a second time if the first time fails." On Windows Vista, sometimes deletes
|
* just means "try a second time if the first time fails, and if that fails then try to delete
|
||||||
* fail but then succeed if you just try again. Given that delete failure is a rare occurance,
|
* when the virtual machine terminates." On Windows Vista, sometimes deletes fail but then
|
||||||
* we can implement this hacky workaround without any negative consequences for normal
|
* succeed if you just try again. Given that delete failure is a rare occurrence, we can
|
||||||
* behavior.
|
* implement this hacky workaround without any negative consequences for normal behavior.
|
||||||
*/
|
*/
|
||||||
public static boolean deleteHarder (File file) {
|
public static boolean deleteHarder (File file) {
|
||||||
// if at first you don't succeed... try, try again
|
// if at first you don't succeed... try, try again
|
||||||
return file.delete() || file.delete();
|
boolean deleted = (file.delete() || file.delete());
|
||||||
|
if (!deleted) {
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user