From 070ebeb21c6b7f7c67c77b8b60f48b854d470e47 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Wed, 3 Apr 2013 16:09:40 +0200 Subject: [PATCH] NPE check for parentFile and better name --- .../intellij/openapi/vfs/newvfs/persistent/FSRecords.java | 6 +++--- platform/util/src/com/intellij/util/io/IOUtil.java | 7 ++++--- .../util/src/com/intellij/util/io/PersistentHashMap.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java index f73bbdd6bb98..1216263b4a0b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java @@ -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"); diff --git a/platform/util/src/com/intellij/util/io/IOUtil.java b/platform/util/src/com/intellij/util/io/IOUtil.java index 65228ce214ba..f93642a1d60e 100644 --- a/platform/util/src/com/intellij/util/io/IOUtil.java +++ b/platform/util/src/com/intellij/util/io/IOUtil.java @@ -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) { diff --git a/platform/util/src/com/intellij/util/io/PersistentHashMap.java b/platform/util/src/com/intellij/util/io/PersistentHashMap.java index e09d36d2f099..56689a5de85f 100644 --- a/platform/util/src/com/intellij/util/io/PersistentHashMap.java +++ b/platform/util/src/com/intellij/util/io/PersistentHashMap.java @@ -284,7 +284,7 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< } public static void deleteFilesStartingWith(@NotNull File prefixFile) { - IOUtil.deleteWithSubordinates(prefixFile); + IOUtil.deleteAllFilesStartingWith(prefixFile); } @NotNull