propagate from branch 'i2p.i2p' (head e014bb054baa0d8e844e9a97ad6f5b04ed7c0e56)

to branch 'i2p.i2p.zzz.test' (head 1e0af137b9c4c873fea72d661f2ee351a640734f)
This commit is contained in:
zzz
2011-07-19 21:18:14 +00:00
18 changed files with 226 additions and 110 deletions

View File

@@ -402,7 +402,7 @@ public class CPUID {
}
// copy to install dir, ignore failure
File newFile = new File(I2PAppContext.getGlobalContext().getBaseDir(), filename);
FileUtil.copy(outFile.getAbsolutePath(), newFile.getAbsolutePath(), false, true);
FileUtil.copy(outFile, newFile, false, true);
return true;
}

View File

@@ -193,7 +193,7 @@ public class SingleFileNamingService extends NamingService {
out.write(d.toBase64());
out.newLine();
out.close();
boolean success = rename(tmp, _file);
boolean success = FileUtil.rename(tmp, _file);
if (success) {
for (NamingServiceListener nsl : _listeners) {
nsl.entryChanged(this, hostname, d, options);
@@ -284,7 +284,7 @@ public class SingleFileNamingService extends NamingService {
tmp.delete();
return false;
}
success = rename(tmp, _file);
success = FileUtil.rename(tmp, _file);
if (success) {
for (NamingServiceListener nsl : _listeners) {
nsl.entryRemoved(this, hostname);
@@ -442,24 +442,6 @@ public class SingleFileNamingService extends NamingService {
}
}
private static boolean rename(File from, File to) {
boolean success = false;
boolean isWindows = System.getProperty("os.name").startsWith("Win");
// overwrite fails on windows
if (!isWindows)
success = from.renameTo(to);
if (!success) {
to.delete();
success = from.renameTo(to);
if (!success) {
// hard way
success = FileUtil.copy(from.getAbsolutePath(), to.getAbsolutePath(), true, true);
from.delete();
}
}
return success;
}
private void getReadLock() {
_fileLock.readLock().lock();
}

View File

@@ -19,7 +19,6 @@ import java.io.InputStream;
* @author jrandom
*/
public class Hash extends SimpleDataStructure {
private volatile String _stringified;
private volatile String _base64ed;
private int _cachedHashCode;
@@ -71,7 +70,6 @@ public class Hash extends SimpleDataStructure {
@Override
public void setData(byte[] data) {
super.setData(data);
_stringified = null;
_base64ed = null;
_cachedHashCode = super.hashCode();
}
@@ -79,7 +77,6 @@ public class Hash extends SimpleDataStructure {
@Override
public void readBytes(InputStream in) throws DataFormatException, IOException {
super.readBytes(in);
_stringified = null;
_base64ed = null;
_cachedHashCode = super.hashCode();
}

View File

@@ -400,7 +400,15 @@ public class FileUtil {
public static boolean copy(String source, String dest, boolean overwriteExisting, boolean quiet) {
File src = new File(source);
File dst = new File(dest);
return copy(src, dst, overwriteExisting, quiet);
}
/**
* @param quiet don't log fails to wrapper log if true
* @return true if it was copied successfully
* @since 0.8.8
*/
public static boolean copy(File src, File dst, boolean overwriteExisting, boolean quiet) {
if (dst.exists() && dst.isDirectory())
dst = new File(dst, src.getName());
@@ -429,6 +437,35 @@ public class FileUtil {
}
}
/**
* Try to rename, if it doesn't work then copy and delete the old.
* Always overwrites any existing "to" file.
* Method moved from SingleFileNamingService.
*
* @return true if it was renamed / copied successfully
* @since 0.8.8
*/
public static boolean rename(File from, File to) {
if (!from.exists())
return false;
boolean success = false;
boolean isWindows = System.getProperty("os.name").startsWith("Win");
// overwrite fails on windows
if (!isWindows)
success = from.renameTo(to);
if (!success) {
to.delete();
success = from.renameTo(to);
if (!success) {
// hard way
success = copy(from, to, true, true);
if (success)
from.delete();
}
}
return success;
}
/**
* Usage: FileUtil (delete path | copy source dest | unzip path.zip)
*

View File

@@ -606,7 +606,7 @@ public class NativeBigInteger extends BigInteger {
}
// copy to install dir, ignore failure
File newFile = new File(I2PAppContext.getGlobalContext().getBaseDir(), filename);
FileUtil.copy(outFile.getAbsolutePath(), newFile.getAbsolutePath(), false, true);
FileUtil.copy(outFile, newFile, false, true);
return true;
}