diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-07-21 09:56:34 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-07-21 09:56:34 -0700 |
commit | 4718fa8172ba230dbf0cbb7a786a01514d688992 (patch) | |
tree | 49521945e00cf491d9badfe0369a582f3f1caae8 /src/github | |
parent | c3afd24b4ee51c9bd9e2789dfe26c4d758d57809 (diff) | |
download | dsub-4718fa8172ba230dbf0cbb7a786a01514d688992.tar.gz dsub-4718fa8172ba230dbf0cbb7a786a01514d688992.tar.bz2 dsub-4718fa8172ba230dbf0cbb7a786a01514d688992.zip |
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.
Diffstat (limited to 'src/github')
-rw-r--r-- | src/github/daneren2005/dsub/util/Util.java | 30 |
1 files changed, 2 insertions, 28 deletions
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); } } |