code: private void restoreGeneration(FileSystem fs, Path perm, long startGen)
        throws IOException {
  
      FileStatus[] fileStatus = fs.listStatus(perm, new PathFilter() {
        public boolean accept(Path path) {
          return LuceneUtil.isSegmentsFile(path.getName());
        }
      });
  
      // remove the segments_N files whose generation are greater than
      // the starting generation
      for (int i = 0; i < fileStatus.length; i++) {
        Path path = fileStatus[i].getPath();
        if (startGen < LuceneUtil.generationFromSegmentsFileName(path.getName())) {
          fs.delete(path);
        }
      }
  
      // always remove segments.gen in case last failed try removed segments_N
      // but not segments.gen, and segments.gen will be overwritten anyway.
      Path segmentsGenFile = new Path(LuceneUtil.IndexFileNames.SEGMENTS_GEN);
      if (fs.exists(segmentsGenFile)) {
        fs.delete(segmentsGenFile);
      }
    }
docs: once the unwanted segments_N files are deleted