From 4718fa8172ba230dbf0cbb7a786a01514d688992 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 21 Jul 2014 09:56:34 -0700 Subject: Get rid of renameTo atomic copy fallback There should be no case where renameTo fails, but you want to just go ahead with the atomic copy. If it fails it is because something still has a lock on the file, and in that case the atomicCopy fails as well and throws the IOError up and causes other issues. --- src/github/daneren2005/dsub/util/Util.java | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'src/github') diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index f8e4cf95..eceb5d46 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -564,35 +564,9 @@ public final class Util { return count; } - public static void atomicCopy(File from, File to) throws IOException { - FileInputStream in = null; - FileOutputStream out = null; - File tmp = null; - try { - tmp = new File(to.getPath() + ".tmp"); - in = new FileInputStream(from); - out = new FileOutputStream(tmp); - in.getChannel().transferTo(0, from.length(), out.getChannel()); - out.close(); - if (!tmp.renameTo(to)) { - throw new IOException("Failed to rename " + tmp + " to " + to); - } - Log.i(TAG, "Copied " + from + " to " + to); - } catch (IOException x) { - close(out); - delete(to); - throw x; - } finally { - close(in); - close(out); - delete(tmp); - } - } public static void renameFile(File from, File to) throws IOException { - if(from.renameTo(to)) { - Log.i(TAG, "Renamed " + from + " to " + to); - } else { - atomicCopy(from, to); + if(!from.renameTo(to)) { + Log.i(TAG, "Failed to rename " + from + " to " + to); } } -- cgit v1.2.3