NPE check for parentFile and better name

This commit is contained in:
Maxim.Mossienko
2013-04-03 16:10:31 +02:00
parent 31149c9dad
commit 070ebeb21c
3 changed files with 8 additions and 7 deletions
@@ -44,7 +44,7 @@ import java.io.*;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import static com.intellij.util.io.IOUtil.deleteWithSubordinates;
import static com.intellij.util.io.IOUtil.deleteAllFilesStartingWith;
@SuppressWarnings({"PointlessArithmeticExpression", "HardCodedStringLiteral"})
public class FSRecords implements Forceable {
@@ -237,10 +237,10 @@ public class FSRecords implements Forceable {
closeFiles();
boolean deleted = FileUtil.delete(getCorruptionMarkerFile());
deleted &= deleteWithSubordinates(namesFile);
deleted &= deleteAllFilesStartingWith(namesFile);
deleted &= AbstractStorage.deleteFiles(attributesFile.getCanonicalPath());
deleted &= AbstractStorage.deleteFiles(contentsFile.getCanonicalPath());
deleted &= deleteWithSubordinates(recordsFile);
deleted &= deleteAllFilesStartingWith(recordsFile);
if (!deleted) {
throw new IOException("Cannot delete filesystem storage files");
@@ -134,14 +134,15 @@ public class IOUtil {
return c < 128;
}
public static boolean deleteWithSubordinates(File file) {
public static boolean deleteAllFilesStartingWith(File file) {
final String baseName = file.getName();
final File[] files = file.getParentFile().listFiles(new FileFilter() {
File parentFile = file.getParentFile();
final File[] files = parentFile != null ? parentFile.listFiles(new FileFilter() {
@Override
public boolean accept(final File pathname) {
return pathname.getName().startsWith(baseName);
}
});
}): null;
boolean ok = true;
if (files != null) {
@@ -284,7 +284,7 @@ public class PersistentHashMap<Key, Value> extends PersistentEnumeratorDelegate<
}
public static void deleteFilesStartingWith(@NotNull File prefixFile) {
IOUtil.deleteWithSubordinates(prefixFile);
IOUtil.deleteAllFilesStartingWith(prefixFile);
}
@NotNull