@Override public void deleteFile(String name) throws IOException { in.deleteFile(name); }
private void deleteFile(String fileName) throws IOException { try { directory.deleteFile(fileName); } catch (NoSuchFileException | FileNotFoundException e) { if (Constants.WINDOWS) { // TODO: can we remove this OS-specific hacky logic? If windows deleteFile is buggy, we should instead contain this workaround in // a WindowsFSDirectory ... // LUCENE-6684: we suppress this assert for Windows, since a file could be in a confusing "pending delete" state, where we already // deleted it once, yet it still shows up in directory listings, and if you try to delete it again you'll hit NSFE/FNFE: } else { throw e; } } }
/** * Deletes all given files, suppressing all thrown IOExceptions. * <p> * Note that the files should not be null. */ public static void deleteFilesIgnoringExceptions(Directory dir, Collection<String> files) { for(String name : files) { try { dir.deleteFile(name); } catch (Throwable ignored) { // ignore } } }
@Override public void deleteFile(String name) throws IOException { in.deleteFile(name); createdFileNames.remove(name); }
@Override public void deleteFile( String name ) throws IOException { delegate.deleteFile( name ); }
@Override public void deleteFile(String name) throws IOException { if (getDirectory(name) == primaryDir) { primaryDir.deleteFile(name); } else { secondaryDir.deleteFile(name); } }
@Override public void destroy() throws IOException { if (sharedReader != null) { // At this point, the shared reader should have done a full sweep of the file: assert nextSharedRead == count; sharedReader.close(); sharedReader = null; } tempDir.deleteFile(name); }
@Override public void deleteFile(String name) throws IOException { writeLock.ensureValid(); in.deleteFile(name); }
private synchronized void clearPriorSnapshots() throws IOException { for(String file : dir.listAll()) { if (file.startsWith(SNAPSHOTS_PREFIX)) { dir.deleteFile(file); } } }
@Override public synchronized void deleteFile(String name) throws IOException { if (VERBOSE) { System.out.println("nrtdir.deleteFile name=" + name); } if (cache.fileNameExists(name)) { cache.deleteFile(name); } else { in.deleteFile(name); } }
/** * Removes content of the lucene directory denoted by the given {@link File file}. This might seem unnecessary * since we cleanup the folder using {@link FileSystemAbstraction file system} but in fact for testing we often use * in-memory directories whose content can't be removed via the file system. * <p> * Uses {@link FileUtils#windowsSafeIOOperation(FileUtils.Operation)} underneath. * * @param folder the path to the directory to cleanup. * @throws IOException if removal operation fails. */ private void cleanupLuceneDirectory( File folder ) throws IOException { try ( Directory dir = directoryFactory.open( folder ) ) { String[] indexFiles = dir.listAll(); for ( String indexFile : indexFiles ) { FileUtils.windowsSafeIOOperation( () -> dir.deleteFile( indexFile ) ); } } } }
/** * Deletes all given file names. Some of the * file names may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param dir Directory to delete files from * @param names file names to delete */ public static void deleteFiles(Directory dir, Collection<String> names) throws IOException { Throwable th = null; for (String name : names) { if (name != null) { try { dir.deleteFile(name); } catch (Throwable t) { th = useOrSuppress(th, t); } } } if (th != null) { throw rethrowAlways(th); } }
protected void dropCorruptMarkerFiles(Terminal terminal, Path path, Directory directory, boolean clean) throws IOException { if (clean) { confirm("This shard has been marked as corrupted but no corruption can now be detected.\n" + "This may indicate an intermittent hardware problem. The corruption marker can be \n" + "removed, but there is a risk that data has been undetectably lost.\n\n" + "Are you taking a risk of losing documents and proceed with removing a corrupted marker ?", terminal); } String[] files = directory.listAll(); boolean found = false; for (String file : files) { if (file.startsWith(Store.CORRUPTED)) { directory.deleteFile(file); terminal.println("Deleted corrupt marker " + file + " from " + path); } } }
/** * This method removes all lucene files from the given directory. It will first try to delete all commit points / segments * files to ensure broken commits or corrupted indices will not be opened in the future. If any of the segment files can't be deleted * this operation fails. */ public static void cleanLuceneIndex(Directory directory) throws IOException { try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) { for (final String file : directory.listAll()) { if (file.startsWith(IndexFileNames.SEGMENTS) || file.equals(IndexFileNames.OLD_SEGMENTS_GEN)) { directory.deleteFile(file); // remove all segment_N files } } } try (IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(Lucene.STANDARD_ANALYZER) .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) .setMergePolicy(NoMergePolicy.INSTANCE) // no merges .setCommitOnClose(false) // no commits .setOpenMode(IndexWriterConfig.OpenMode.CREATE))) // force creation - don't append... { // do nothing and close this will kick of IndexFileDeleter which will remove all pending files } }
/** * Deletes all corruption markers from this store. */ public void removeCorruptionMarker() throws IOException { ensureOpen(); final Directory directory = directory(); IOException firstException = null; final String[] files = directory.listAll(); for (String file : files) { if (file.startsWith(CORRUPTED)) { try { directory.deleteFile(file); } catch (IOException ex) { if (firstException == null) { firstException = ex; } else { firstException.addSuppressed(ex); } } } } if (firstException != null) { throw firstException; } }
foundSegmentFiles++; if (file.equals(si.getSegmentsFileName()) == false) { directory.deleteFile(file); // remove all segment_N files except of the one we wanna keep
} finally { if (success) { tempDir.deleteFile(unsorted.getName()); } else { IOUtils.deleteFilesIgnoringExceptions(tempDir, unsorted.getName()); } finally { if (success2) { tempDir.deleteFile(sorted); } else { IOUtils.deleteFilesIgnoringExceptions(tempDir, sorted);
if (deleteIfExistFiles.contains(physicalName)) { logger.trace("[{}] [{}] deleting pre-existing file [{}]", shardId, snapshotId, physicalName); store.directory().deleteFile(physicalName); store.directory().deleteFile(storeFile); } catch (IOException e) { logger.warn("[{}] failed to delete file [{}] during snapshot cleanup", snapshotId, storeFile);
private static void deleteAllFiles(Directory dir) throws IOException { for (String fileName : dir.listAll()){ dir.deleteFile(fileName); } } }
tempDir.deleteFile(tempInput.getName()); IOUtils.closeWhileHandlingException(reader, writer); try { tempDir.deleteFile(tempInput.getName()); } finally { tempDir.deleteFile(tempSortedFileName);