Java Code Examples for com.intellij.openapi.util.io.FileUtil#deleteWithRenaming()
The following examples show how to use
com.intellij.openapi.util.io.FileUtil#deleteWithRenaming() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecompileAndAttachAction.java From decompile-and-attach with MIT License | 5 votes |
private File copy(Project project, String baseDirPath, VirtualFile sourceVF, File tmpJarFile, String filename) throws IOException { String libraryName = filename.replace(".jar", "-sources.jar"); String fullPath = baseDirPath + File.separator + libraryName; File result = new File(fullPath); if (result.exists()) { FileUtil.deleteWithRenaming(result); result = new File(fullPath); result.createNewFile(); } FileUtil.copy(tmpJarFile, result); return result; }
Example 2
Source File: PersistentUtil.java From consulo with Apache License 2.0 | 5 votes |
public static boolean deleteWithRenamingAllFilesStartingWith(@Nonnull 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; }
Example 3
Source File: VcsLogCachesInvalidator.java From consulo with Apache License 2.0 | 5 votes |
public synchronized boolean isValid() { if (PersistentUtil.getCorruptionMarkerFile().exists()) { boolean deleted = FileUtil.deleteWithRenaming(PersistentUtil.LOG_CACHE); if (!deleted) { // if could not delete caches, ensure that corruption marker is still there FileUtil.createIfDoesntExist(PersistentUtil.getCorruptionMarkerFile()); } else { LOG.debug("Deleted VCS Log caches at " + PersistentUtil.LOG_CACHE); } return deleted; } return true; }
Example 4
Source File: VfsDependentEnum.java From consulo with Apache License 2.0 | 5 votes |
private void invalidate(@Nonnull Throwable e, boolean vfsRebuildOnException) { if (!myMarkedForInvalidation) { myMarkedForInvalidation = true; // exception will be rethrown in this call FileUtil.deleteWithRenaming(myFile); // better alternatives ? if (vfsRebuildOnException) { FSRecords.requestVfsRebuild(e); } } }
Example 5
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
/** * @return true if registered index requires full rebuild for some reason, e.g. is just created or corrupted */ private static <K, V> void registerIndexer(Project project, @Nonnull final FileBasedIndexExtension<K, V> extension, @Nonnull IndexConfiguration state, @Nonnull IndicesRegistrationResult registrationStatusSink) throws IOException { final ID<K, V> name = extension.getName(); final int version = extension.getVersion(); final File versionFile = IndexInfrastructure.getVersionFile(name); if (IndexingStamp.versionDiffers(name, version)) { final boolean versionFileExisted = versionFile.exists(); if (versionFileExisted) { registrationStatusSink.registerIndexAsChanged(name); } else { registrationStatusSink.registerIndexAsInitiallyBuilt(name); } if (extension.hasSnapshotMapping() && versionFileExisted) { FileUtil.deleteWithRenaming(IndexInfrastructure.getPersistentIndexRootDir(name)); } File rootDir = IndexInfrastructure.getIndexRootDir(name); if (versionFileExisted) FileUtil.deleteWithRenaming(rootDir); IndexingStamp.rewriteVersion(name, version); } else { registrationStatusSink.registerIndexAsUptoDate(name); } initIndexStorage(extension, version, state); }
Example 6
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void prepare() { // PersistentFS lifecycle should contain FileBasedIndex lifecycle, so, // 1) we call for it's instance before index creation to make sure it's initialized // 2) we dispose FileBasedIndex before PersistentFS disposing PersistentFSImpl fs = (PersistentFSImpl)ManagingFS.getInstance(); Disposable disposable = () -> performShutdown(); ApplicationManager.getApplication().addApplicationListener(new ApplicationListener() { @Override public void writeActionStarted(@Nonnull Object action) { myUpToDateIndicesForUnsavedOrTransactedDocuments.clear(); } }, disposable); Disposer.register(fs, disposable); initAssociatedDataForExtensions(); File indexRoot = ContainerPathManager.get().getIndexRoot(); PersistentIndicesConfiguration.loadConfiguration(); final File corruptionMarker = new File(indexRoot, CORRUPTION_MARKER_NAME); currentVersionCorrupted = IndexInfrastructure.hasIndices() && corruptionMarker.exists(); if (currentVersionCorrupted) { FileUtil.deleteWithRenaming(indexRoot); indexRoot.mkdirs(); // serialization manager is initialized before and use removed index root so we need to reinitialize it SerializationManagerEx.getInstanceEx().reinitializeNameStorage(); ID.reinitializeDiskStorage(); PersistentIndicesConfiguration.saveConfiguration(); FileUtil.delete(corruptionMarker); } }
Example 7
Source File: StubIndexImpl.java From consulo with Apache License 2.0 | 4 votes |
private static <K> void onExceptionInstantiatingIndex(@Nonnull StubIndexKey<K, ?> indexKey, int version, @Nonnull File indexRootDir, @Nonnull Exception e) throws IOException { LOG.info(e); FileUtil.deleteWithRenaming(indexRootDir); IndexingStamp.rewriteVersion(indexKey, version); // todo snapshots indices }
Example 8
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 4 votes |
private static <K, V> void initIndexStorage(@Nonnull FileBasedIndexExtension<K, V> extension, int version, @Nonnull IndexConfiguration state) throws IOException { VfsAwareMapIndexStorage<K, V> storage = null; final ID<K, V> name = extension.getName(); boolean contentHashesEnumeratorOk = false; for (int attempt = 0; attempt < 2; attempt++) { try { if (extension.hasSnapshotMapping()) { ContentHashesSupport.initContentHashesEnumerator(); contentHashesEnumeratorOk = true; } storage = new VfsAwareMapIndexStorage<>(IndexInfrastructure.getStorageFile(name), extension.getKeyDescriptor(), extension.getValueExternalizer(), extension.getCacheSize(), extension.keyIsUniqueForIndexedFile(), extension.traceKeyHashToVirtualFileMapping()); final InputFilter inputFilter = extension.getInputFilter(); final Set<FileType> addedTypes; if (inputFilter instanceof FileBasedIndex.FileTypeSpecificInputFilter) { addedTypes = new THashSet<>(); ((FileBasedIndex.FileTypeSpecificInputFilter)inputFilter).registerFileTypesUsedForIndexing(type -> { if (type != null) addedTypes.add(type); }); } else { addedTypes = null; } UpdatableIndex<K, V, FileContent> index = createIndex(extension, new MemoryIndexStorage<>(storage, name)); ProvidedIndexExtension<K, V> providedExtension = ProvidedIndexExtensionLocator.findProvidedIndexExtensionFor(extension); if (providedExtension != null) { index = ProvidedIndexExtension.wrapWithProvidedIndex(providedExtension, extension, index); } state.registerIndex(name, index, (p, file) -> file instanceof VirtualFileWithId && inputFilter.acceptInput(p, file) && !GlobalIndexFilter.isExcludedFromIndexViaFilters(file, name), version + GlobalIndexFilter.getFiltersVersion(name), addedTypes); break; } catch (Exception e) { LOG.info(e); boolean instantiatedStorage = storage != null; try { if (storage != null) storage.close(); storage = null; } catch (Exception ignored) { } FileUtil.deleteWithRenaming(IndexInfrastructure.getIndexRootDir(name)); if (extension.hasSnapshotMapping() && (!contentHashesEnumeratorOk || instantiatedStorage)) { FileUtil.deleteWithRenaming(IndexInfrastructure.getPersistentIndexRootDir(name)); // todo there is possibility of corruption of storage and content hashes } IndexingStamp.rewriteVersion(name, version); } } }