/** @see IndexReader#listCommits */
public new static ICollection <IndexCommitPoint> ListCommits(Directory dir)
{
string[] files = dir.List();
if (files == null)
{
throw new System.IO.IOException("cannot read directory " + dir + ": list() returned null");
}
ICollection <IndexCommitPoint> commits = new List <IndexCommitPoint>();
SegmentInfos latest = new SegmentInfos();
latest.Read(dir);
long currentGen = latest.GetGeneration();
commits.Add(new ReaderCommit(latest, dir));
for (int i = 0; i < files.Length; i++)
{
String fileName = files[i];
if (fileName.StartsWith(IndexFileNames.SEGMENTS) &&
!fileName.Equals(IndexFileNames.SEGMENTS_GEN) &&
SegmentInfos.GenerationFromSegmentsFileName(fileName) < currentGen)
{
SegmentInfos sis = new SegmentInfos();
try
{
// IOException allowed to throw there, in case
// segments_N is corrupt
sis.Read(dir, fileName);
}
catch (System.Exception)
{
// LUCENE-948: on NFS (and maybe others), if
// you have writers switching back and forth
// between machines, it's very likely that the
// dir listing will be stale and will claim a
// file segments_X exists when in fact it
// doesn't. So, we catch this and handle it
// as if the file does not exist
sis = null;
}
if (sis != null)
{
commits.Add(new ReaderCommit(sis, dir));
}
}
}
return(commits);
}