* i2psnark:

- Fix NPE after create file failure
      - Sanitize more characters in file names
This commit is contained in:
zzz
2010-02-26 16:44:49 +00:00
parent 5fd4488e08
commit 299214aa1d
3 changed files with 34 additions and 6 deletions

View File

@ -425,9 +425,18 @@ public class SnarkManager implements Snark.CompleteListener {
FileInputStream fis = null;
try {
fis = new FileInputStream(sfile);
} catch (IOException ioe) {
// catch this here so we don't try do delete it below
addMessage(_("Cannot open \"{0}\"", sfile.getName()) + ": " + ioe.getMessage());
return;
}
try {
MetaInfo info = new MetaInfo(fis);
fis.close();
fis = null;
try {
fis.close();
fis = null;
} catch (IOException e) {}
if (!TrackerClient.isValidAnnounce(info.getAnnounce())) {
if (_util.shouldUseOpenTrackers() && _util.getOpenTrackers() != null) {

View File

@ -420,13 +420,29 @@ public class Storage
}
}
private static final char[] ILLEGAL = new char[] {
'<', '>', ':', '"', '/', '\\', '|', '?', '*',
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
/**
* Removes 'suspicious' characters from the give file name.
* Removes 'suspicious' characters from the given file name.
* http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
*/
private static String filterName(String name)
{
// XXX - Is this enough?
return name.replace(File.separatorChar, '_');
if (name.equals(".") || name.equals(" "))
return "_";
String rv = name;
if (rv.startsWith("."))
rv = '_' + rv.substring(1);
if (rv.endsWith(".") || rv.endsWith(" "))
rv = rv.substring(0, rv.length() - 1) + '_';
for (int i = 0; i < ILLEGAL.length; i++) {
if (rv.indexOf(ILLEGAL[i]) >= 0)
rv = rv.replace(ILLEGAL[i], '_');
}
return rv;
}
private File createFileFromNames(File base, List names) throws IOException
@ -577,6 +593,9 @@ public class Storage
if (rafs == null) return;
for (int i = 0; i < rafs.length; i++)
{
// if we had an IOE in check(), the RAFlock may be null
if (RAFlock[i] == null)
continue;
try {
synchronized(RAFlock[i]) {
closeRAF(i);

View File

@ -179,7 +179,7 @@ public class BEValue
if (value instanceof byte[])
{
byte[] bs = (byte[])value;
// XXX - Stupid heuristic...
// XXX - Stupid heuristic... and not UTF-8
if (bs.length <= 12)
valueString = new String(bs);
else