aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-21 09:56:34 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-21 09:56:34 -0700
commit4718fa8172ba230dbf0cbb7a786a01514d688992 (patch)
tree49521945e00cf491d9badfe0369a582f3f1caae8 /src/github
parentc3afd24b4ee51c9bd9e2789dfe26c4d758d57809 (diff)
downloaddsub-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.java30
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);
}
}