/** * Returns <code>true</code> if an index exists at the specified directory. * If the directory does not exist or if there is no index in it. * @param directory the directory to check for an index * @return <code>true</code> if an index exists; <code>false</code> otherwise * @throws IOException if there is a problem with accessing the index */ public static boolean indexExists(Directory directory) throws IOException { return directory.fileExists("segments"); }
/** * Returns true if this segment is stored as a compound * file; else, false. */ boolean getUseCompoundFile() throws IOException { if (isCompoundFile == NO) { return false; } else if (isCompoundFile == YES) { return true; } else { return dir.fileExists(name + "." + IndexFileNames.COMPOUND_FILE_EXTENSION); } }
@Override public boolean fileExists(final String fileName) throws IOException { return directory.fileExists(fileName); }
@Override public boolean fileExists(String name) throws IOException { if (shouldPerformOperationOnActualDirectory(name)) { return dir.fileExists(name); } if (localCacheDir.fileExists(name)) { return true; } return dir.fileExists(name); }
private void addIfExists(List files, String fileName) throws IOException { if (dir.fileExists(fileName)) files.add(fileName); }
private long getSkippedFilesSize() { long size = 0; for (String name : skippedFiles){ try{ if (local.fileExists(name)){ size += local.fileLength(name); } } catch (Exception ignore){ } } return size; }
public static void deleteTimestamp( Directory directory ) throws IOException { if ( directory.fileExists( TIMESTAMP_FILE ) ) { directory.deleteFile( TIMESTAMP_FILE ); } }
private long getSkippedFilesSize() { long size = 0; for (String name : skippedFiles){ try{ if (local.fileExists(name)){ size += local.fileLength(name); } } catch (Exception ignore){ } } return size; }
public boolean isReceivingUpdates() { try { return getIndexDirectory().fileExists( INDEX_UPDATER_PROPERTIES_FILE ); } catch ( IOException e ) { return false; } } }
private void fetchFileIfNotExists(String name) throws IOException { synchronized (monitors[Math.abs(name.hashCode()) % monitors.length]) { if (localCacheDir.fileExists(name)) { return; } if (log.isTraceEnabled()) { log.trace(logMessage("Fetching [" + name + "] to local cache")); } copy(dir, localCacheDir, name); } }
public void clearWrapper() throws IOException { if (log.isTraceEnabled()) { log.trace(logMessage("Clearing local cache")); } String[] list = localCacheDir.list(); for (String name : list) { synchronized (monitors[Math.abs(name.hashCode()) % monitors.length]) { if (localCacheDir.fileExists(name)) { localCacheDir.deleteFile(name); } } } }
Directory directory = FSDirectory.open(folder); if (directory.fileExists(IndexWriter.WRITE_LOCK_NAME)) { directory.clearLock(IndexWriter.WRITE_LOCK_NAME); log.warn("Existing write.lock at [" + folder.getAbsolutePath() + "] has been found and removed. This is a likely result of non-gracefully terminated server. Check for index discrepancies!"); } directory.close();
@Override public boolean fileExists(String name) throws IOException { editingContext().lock(); try { return _wrapped.fileExists(name); } finally { editingContext().unlock(); } }
private final void openNorms(Directory cfsDir) throws IOException { for (int i = 0; i < fieldInfos.size(); i++) { FieldInfo fi = fieldInfos.fieldInfo(i); if (fi.isIndexed) { String fileName = segment + ".f" + fi.number; // look first for re-written file, then in compound format Directory d = directory().fileExists(fileName) ? directory() : cfsDir; norms.put(fi.name, new Norm(d.openFile(fileName), fi.number)); } } }
private long segmentSize(String segmentName) throws IOException { // Used only when infoStream != null assert infoStream != null; long size = directory.fileLength(segmentName + ".tii") + directory.fileLength(segmentName + ".tis") + directory.fileLength(segmentName + ".frq") + directory.fileLength(segmentName + ".prx"); final String normFileName = segmentName + ".nrm"; if (directory.fileExists(normFileName)) size += directory.fileLength(normFileName); return size; }
private long segmentSize(String segmentName) throws IOException { // Used only when infoStream != null assert infoStream != null; long size = directory.fileLength(segmentName + ".tii") + directory.fileLength(segmentName + ".tis") + directory.fileLength(segmentName + ".frq") + directory.fileLength(segmentName + ".prx"); final String normFileName = segmentName + ".nrm"; if (directory.fileExists(normFileName)) size += directory.fileLength(normFileName); return size; }
TermVectorsReader(Directory d, String segment, FieldInfos fieldInfos) throws IOException { if (d.fileExists(segment + TermVectorsWriter.TVX_EXTENSION)) { tvx = d.openFile(segment + TermVectorsWriter.TVX_EXTENSION); checkValidFormat(tvx); tvd = d.openFile(segment + TermVectorsWriter.TVD_EXTENSION); checkValidFormat(tvd); tvf = d.openFile(segment + TermVectorsWriter.TVF_EXTENSION); checkValidFormat(tvf); size = (int) tvx.length() / 8; } this.fieldInfos = fieldInfos; }
@Test public void extraLocalFiles() throws Exception{ byte[] t1L = writeFile(local, "t1", 100); byte[] t3R = writeFile(remote, "t3", 140); writeFile(local, "t3", t3R); new IndexSanityChecker("/foo", local, remote).check(); //t1 exist in local but not in remote //it must be removed assertFalse(local.fileExists("t1")); //t3 should remain present assertTrue(remote.fileExists("t3")); }
@Test public void validDirs() throws Exception{ byte[] t1 = writeFile(local, "t1", 100); writeFile(remote, "t1", t1); assertTrue(new IndexSanityChecker("/foo", local, remote).check()); assertTrue(local.fileExists("t1")); assertTrue(remote.fileExists("t1")); }
private void assertFile(Directory dir, String file, byte[] expected) throws IOException { assertTrue(dir.fileExists(file)); assertEquals(expected.length, dir.fileLength(file)); IndexInput in = dir.openInput(file, IOContext.DEFAULT); byte[] data = new byte[expected.length]; in.readBytes(data, 0, data.length); in.close(); assertTrue(Arrays.equals(expected, data)); }