Introduce deleteWithRenamingAllFilesStartingWith for that purpose.
fatalErrorHandler, disposableParent);
}
- @NotNull
- public static Collection<File> getStorageFiles(@NotNull String logId) {
- return Collections.singletonList(getStorageFile(TRIGRAMS, logId));
- }
-
@Nullable
public ValueContainer.IntIterator getCommitsForSubstring(@NotNull String string) throws StorageException {
MyTrigramProcessor trigramProcessor = new MyTrigramProcessor();
Page.PAGE_SIZE, null, getVersion());
}
- @NotNull
- public static Collection<File> getStorageFiles(@NotNull String logId) {
- return Arrays.asList(getStorageFile(INDEX_PATHS_IDS, logId),
- getStorageFile(PATHS, logId));
- }
-
@Override
public void flush() throws StorageException {
super.flush();
}
private static void cleanup(@NotNull String logId) {
- IOUtil.deleteAllFilesStartingWith(getStorageFile(INDEX, COMMITS, logId, getVersion(), false));
- IOUtil.deleteAllFilesStartingWith(getStorageFile(INDEX, MESSAGES, logId, VcsLogStorageImpl.VERSION + MESSAGES_VERSION, false));
-
- VcsLogMessagesTrigramIndex.getStorageFiles(logId).forEach(IOUtil::deleteAllFilesStartingWith);
- VcsLogUserIndex.getStorageFiles(logId).forEach(IOUtil::deleteAllFilesStartingWith);
- VcsLogPathsIndex.getStorageFiles(logId).forEach(IOUtil::deleteAllFilesStartingWith);
+ if (!PersistentUtil.cleanupStorageFiles(INDEX, logId)) {
+ LOG.error("Could not clean up storage files in " + new File(PersistentUtil.LOG_CACHE, INDEX) + " starting with " + logId);
+ }
}
}
((UserIndexer)myIndexer).setFatalErrorConsumer(e -> consumer.consume(this, e));
}
- @NotNull
- public static Collection<File> getStorageFiles(@NotNull String logId) {
- return Collections.singletonList(getStorageFile(USERS, logId));
- }
-
public TIntHashSet getCommitsForUsers(@NotNull Set<VcsUser> users) throws IOException, StorageException {
Set<Integer> ids = ContainerUtil.newHashSet();
for (VcsUser user : users) {
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PathUtilRt;
storageFile);
}
+ public static boolean deleteWithRenamingAllFilesStartingWith(@NotNull File baseFile) {
+ File parentFile = baseFile.getParentFile();
+ if (parentFile == null) return false;
+
+ File[] files = parentFile.listFiles(pathname -> pathname.getName().startsWith(baseFile.getName()));
+ if (files == null) return true;
+
+ boolean deleted = true;
+ for (File f : files) {
+ deleted &= FileUtil.deleteWithRenaming(f);
+ }
+ return deleted;
+ }
+
+ // this method cleans up all storage files for a project in a specified subdir
+ // it assumes that these storage files all start with "safeLogId."
+ // as method getStorageFile creates them
+ // so these two methods should be changed in sync
+ public static boolean cleanupStorageFiles(@NotNull String subdirName, @NotNull String id) {
+ File subdir = new File(LOG_CACHE, subdirName);
+ String safeLogId = PathUtilRt.suggestFileName(id, true, true);
+ return deleteWithRenamingAllFilesStartingWith(new File(subdir, safeLogId + "."));
+ }
+
+ // do not forget to change cleanupStorageFiles method when editing this one
@NotNull
public static File getStorageFile(@NotNull String subdirName,
@NotNull String kind,