grib/src/main/java/ucar/nc2/grib/collection/GribPartitionBuilder.java
private boolean needsUpdate(CollectionUpdateType ff, File collectionIndexFile) throws IOException {
    long collectionLastModified = collectionIndexFile.lastModified();
    Set<String> newFileSet = new HashSet<>();
    for (MCollection dcm : partitionManager.makePartitions(CollectionUpdateType.test)) {
      String partitionIndexFilename = StringUtil2.replace(dcm.getIndexFilename(GribCdmIndex.NCX_SUFFIX), '\\', "/");
      File partitionIndexFile = GribIndexCache.getExistingFileOrCache(partitionIndexFilename);
      if (partitionIndexFile == null)                                 // make sure each partition has an index
        return true;
      if (collectionLastModified < partitionIndexFile.lastModified())  // and the partition index is earlier than the collection index
        return true;
      newFileSet.add(partitionIndexFilename);
    }

    if (ff == CollectionUpdateType.testIndexOnly) return false;

    // now see if any files were deleted
    GribCdmIndex reader = new GribCdmIndex(logger);
    List<MFile> oldFiles = new ArrayList<>();
    reader.readMFiles(collectionIndexFile.toPath(), oldFiles);
    Set<String> oldFileSet = new HashSet<>();
    for (MFile oldFile : oldFiles) {
      if (!newFileSet.contains(oldFile.getPath()))
        return true;  // got deleted - must recreate the index
      oldFileSet.add(oldFile.getPath());
    }

    // now see if any files were added
    for (String newFilename : newFileSet) {
      if (!oldFileSet.contains(newFilename))
        return true;  // got added - must recreate the index
    }

    return false;
  }
private boolean needsUpdate(CollectionUpdateType ff, File collectionIndexFile) throws IOException {
    long collectionLastModified = collectionIndexFile.lastModified();
    Set<String> newFileSet = new HashSet<>();
    for (MCollection dcm : partitionManager.makePartitions(CollectionUpdateType.test)) {
      String partitionIndexFilename = StringUtil2.replace(dcm.getIndexFilename(GribCdmIndex.NCX_SUFFIX), '\\', "/");
      File partitionIndexFile = GribIndexCache.getExistingFileOrCache(partitionIndexFilename);
      if (partitionIndexFile == null)                                 // make sure each partition has an index
        return true;
      if (collectionLastModified < partitionIndexFile.lastModified())  // and the partition index is earlier than the collection index
        return true;
      newFileSet.add(partitionIndexFilename);
    }

    if (ff == CollectionUpdateType.testIndexOnly) return false;

    // now see if any files were deleted
    GribCdmIndex reader = new GribCdmIndex(logger);
    List<MFile> oldFiles = new ArrayList<>();
    reader.readMFiles(collectionIndexFile.toPath(), oldFiles);
    Set<String> oldFileSet = new HashSet<>();
    for (MFile oldFile : oldFiles) {
      if (!newFileSet.contains(oldFile.getPath()))
        return true;  // got deleted - must recreate the index
      oldFileSet.add(oldFile.getPath());
    }

    // now see if any files were added
    for (String newFilename : newFileSet) {
      if (!oldFileSet.contains(newFilename))
        return true;  // got added - must recreate the index
    }

    return false;
  }
private boolean needsUpdate ( CollectionUpdateType ff , File collectionIndexFile ) throws IOException { long collectionLastModified = collectionIndexFile . lastModified ( ) ; Set < String > newFileSet = new HashSet <> ( ) ; for ( MCollection dcm : partitionManager . makePartitions ( CollectionUpdateType . test ) ) { String partitionIndexFilename = StringUtil2 . replace ( dcm . getIndexFilename ( GribCdmIndex . NCX_SUFFIX ) , ' ' , "/" ) ; File partitionIndexFile = GribIndexCache . getExistingFileOrCache ( partitionIndexFilename ) ; if ( partitionIndexFile == null ) // make sure each partition has an index return true ; if ( collectionLastModified < partitionIndexFile . lastModified ( ) ) // and the partition index is earlier than the collection index return true ; newFileSet . add ( partitionIndexFilename ) ; } if ( ff == CollectionUpdateType . testIndexOnly ) return false ; // now see if any files were deleted GribCdmIndex reader = new GribCdmIndex ( logger ) ; List < MFile > oldFiles = new ArrayList <> ( ) ; reader . readMFiles ( collectionIndexFile . toPath ( ) , oldFiles ) ; Set < String > oldFileSet = new HashSet <> ( ) ; for ( MFile oldFile : oldFiles ) { if ( ! newFileSet . contains ( oldFile . getPath ( ) ) ) return true ; // got deleted - must recreate the index oldFileSet . add ( oldFile . getPath ( ) ) ; } // now see if any files were added for ( String newFilename : newFileSet ) { if ( ! oldFileSet . contains ( newFilename ) ) return true ; // got added - must recreate the index } return false ; }
LOOK need an option to only scan latest last partition or something
LOOK need an option to only scan latest last partition or something