Fix try to delete file while it does not exist anymore (see #2102 and #1713) in reference to this issue

This commit is contained in:
Frederic Bregier 2014-01-20 16:40:14 +01:00 committed by Trustin Lee
parent 0f70921d2a
commit ce39e6409e

View File

@ -238,11 +238,12 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override @Override
public void delete() { public void delete() {
if (! isRenamed) { if (! isRenamed) {
if (file != null) { if (file != null && file.exists()) {
if (!file.delete()) { if (!file.delete()) {
logger.warn("Failed to delete: {}", file); logger.warn("Failed to delete: {}", file);
} }
} }
file = null;
} }
} }
@ -322,6 +323,9 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
if (dest == null) { if (dest == null) {
throw new NullPointerException("dest"); throw new NullPointerException("dest");
} }
if (file == null) {
throw new IOException("No file defined so cannot be renamed");
}
if (!file.renameTo(dest)) { if (!file.renameTo(dest)) {
// must copy // must copy
FileInputStream inputStream = new FileInputStream(file); FileInputStream inputStream = new FileInputStream(file);