@Override public String[] listAll() throws IOException { return in.listAll(); }
@Override public String[] listAll() throws IOException { return delegate.listAll(); }
/** * Returns <code>true</code> if an index likely exists at * the specified directory. Note that if a corrupt index * exists, or if an index in the process of committing * @param directory the directory to check for an index * @return <code>true</code> if an index exists; <code>false</code> otherwise */ public static boolean indexExists(Directory directory) throws IOException { // LUCENE-2812, LUCENE-2727, LUCENE-4738: this logic will // return true in cases that should arguably be false, // such as only IW.prepareCommit has been called, or a // corrupt first commit, but it's too deadly to make // this logic "smarter" and risk accidentally returning // false due to various cases like file description // exhaustion, access denied, etc., because in that // case IndexWriter may delete the entire index. It's // safer to err towards "index exists" than try to be // smart about detecting not-yet-fully-committed or // corrupt indices. This means that IndexWriter will // throw an exception on such indices and the app must // resolve the situation manually: String[] files = directory.listAll(); String prefix = IndexFileNames.SEGMENTS + "_"; for(String file : files) { if (file.startsWith(prefix)) { return true; } } return false; }
private synchronized void clearPriorSnapshots() throws IOException { for(String file : dir.listAll()) { if (file.startsWith(SNAPSHOTS_PREFIX)) { dir.deleteFile(file); } } }
/** * Get the generation of the most recent commit to the * index in this directory (N in the segments_N file). * * @param directory -- directory to search for the latest segments_N file */ public static long getLastCommitGeneration(Directory directory) throws IOException { return getLastCommitGeneration(directory.listAll()); }
@Override public synchronized String[] listAll() throws IOException { final Set<String> files = new HashSet<>(); for(String f : cache.listAll()) { files.add(f); } for(String f : in.listAll()) { files.add(f); } String[] result = files.toArray(new String[files.size()]); Arrays.sort(result); return result; }
private static Set<String> listDir( Directory dir ) throws IOException { String[] files = dir.listAll(); return Stream.of( files ) .filter( file -> !IndexWriter.WRITE_LOCK_NAME.equals( file ) ) .collect( toSet() ); }
Set<String> toDelete = new HashSet<>(); String[] files = directory.listAll();
/** * 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 ) ); } } } }
IOException ioe = null; List<String> snapshotFiles = new ArrayList<>(); for(String file : dir.listAll()) { if (file.startsWith(SNAPSHOTS_PREFIX)) { long gen = Long.parseLong(file.substring(SNAPSHOTS_PREFIX.length()));
final String[] files = dir.listAll();
if ( !ArrayUtil.isEmpty( directory.listAll() ) )
@Test void prepareFolderRemovesFromLucene() throws IOException { File folder = createRandomFolder( testDir.databaseDir() ); Directory dir = createRandomLuceneDir( folder ); assertFalse( ArrayUtil.isEmpty( dir.listAll() ) ); storage.prepareFolder( folder ); assertTrue( fs.fileExists( folder ) ); assertTrue( ArrayUtil.isEmpty( dir.listAll() ) ); }
@Test void openIndexDirectories() throws IOException { File indexFolder = storage.getIndexFolder(); createRandomLuceneDir( indexFolder ).close(); createRandomLuceneDir( indexFolder ).close(); Map<File,Directory> directories = storage.openIndexDirectories(); try { assertEquals( 2, directories.size() ); for ( Directory dir : directories.values() ) { assertFalse( ArrayUtil.isEmpty( dir.listAll() ) ); } } finally { IOUtils.closeAll( directories.values() ); } }
public static boolean isCorruptMarkerFileIsPresent(final Directory directory) throws IOException { boolean found = false; final String[] files = directory.listAll(); for (String file : files) { if (file.startsWith(Store.CORRUPTED)) { found = true; break; } } return found; }
Status result = new Status(); result.dir = dir; String[] files = dir.listAll(); String lastSegmentsFile = SegmentInfos.getLastCommitSegmentsFileName(files); if (lastSegmentsFile == null) {
String[] files = directory.listAll();
private void copy(Directory src, Directory to) throws IOException { for (String file : src.listAll()) { src.copyFrom(src, file, to.toString(), IOContext.DEFAULT); } }