@Test public void testIgnore() throws Exception { PostDownloadPolicy policy = lookupPolicy(); StorageAsset localFile = createTestableFiles( null, null ); Properties request = createRequest(); policy.applyPolicy( ChecksumPolicy.IGNORE, request, localFile ); }
@Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( "resource".equals( request.getProperty( "filetype" ) ) ) { return; } if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown checksum policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( IGNORE.equals( policySetting ) ) { log.debug( "Checksum policy set to IGNORE." ); return; } if ( !localFile.exists() ) { throw new PolicyViolationException( "Checksum policy failure, local file " + localFile.getPath() + " does not exist to check." ); } if ( FAIL.equals( policySetting ) && localFile.isFileBased() ) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.isValidChecksums( algorithms ) ) { return; } for ( ChecksumAlgorithm algorithm : algorithms ) { Path file = checksum.getChecksumFile( algorithm ); try { Files.deleteIfExists( file ); } catch ( IOException e ) { log.error("Could not delete file {}", file); } } try { localFile.getStorage().removeAsset( localFile ); } catch ( IOException e ) { log.error("Could not delete file {}", localFile); } throw new PolicyViolationException( "Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file " + localFile.getPath() + "." ); } if ( FIX.equals( policySetting ) && localFile.isFileBased()) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.fixChecksums( algorithms ).getTotalStatus() != UpdateStatus.ERROR ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); return; } else { throw new PolicyViolationException( "Checksum policy set to FIX, " + "yet unable to update checksums for local file " + localFile.getPath() + "." ); } } throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting + "], please file a bug report." ); }
ChecksumPolicy extends AbstractPolicy implements PostDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( "resource".equals( request.getProperty( "filetype" ) ) ) { return; } if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown checksum policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( IGNORE.equals( policySetting ) ) { log.debug( "Checksum policy set to IGNORE." ); return; } if ( !localFile.exists() ) { throw new PolicyViolationException( "Checksum policy failure, local file " + localFile.getPath() + " does not exist to check." ); } if ( FAIL.equals( policySetting ) && localFile.isFileBased() ) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.isValidChecksums( algorithms ) ) { return; } for ( ChecksumAlgorithm algorithm : algorithms ) { Path file = checksum.getChecksumFile( algorithm ); try { Files.deleteIfExists( file ); } catch ( IOException e ) { log.error("Could not delete file {}", file); } } try { localFile.getStorage().removeAsset( localFile ); } catch ( IOException e ) { log.error("Could not delete file {}", localFile); } throw new PolicyViolationException( "Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file " + localFile.getPath() + "." ); } if ( FIX.equals( policySetting ) && localFile.isFileBased()) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.fixChecksums( algorithms ).getTotalStatus() != UpdateStatus.ERROR ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); return; } else { throw new PolicyViolationException( "Checksum policy set to FIX, " + "yet unable to update checksums for local file " + localFile.getPath() + "." ); } } throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting + "], please file a bug report." ); } }
ChecksumPolicy extends AbstractPolicy implements PostDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( "resource".equals( request.getProperty( "filetype" ) ) ) { return; } if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown checksum policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( IGNORE.equals( policySetting ) ) { log.debug( "Checksum policy set to IGNORE." ); return; } if ( !localFile.exists() ) { throw new PolicyViolationException( "Checksum policy failure, local file " + localFile.getPath() + " does not exist to check." ); } if ( FAIL.equals( policySetting ) && localFile.isFileBased() ) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.isValidChecksums( algorithms ) ) { return; } for ( ChecksumAlgorithm algorithm : algorithms ) { Path file = checksum.getChecksumFile( algorithm ); try { Files.deleteIfExists( file ); } catch ( IOException e ) { log.error("Could not delete file {}", file); } } try { localFile.getStorage().removeAsset( localFile ); } catch ( IOException e ) { log.error("Could not delete file {}", localFile); } throw new PolicyViolationException( "Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file " + localFile.getPath() + "." ); } if ( FIX.equals( policySetting ) && localFile.isFileBased()) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.fixChecksums( algorithms ).getTotalStatus() != UpdateStatus.ERROR ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); return; } else { throw new PolicyViolationException( "Checksum policy set to FIX, " + "yet unable to update checksums for local file " + localFile.getPath() + "." ); } } throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting + "], please file a bug report." ); } ChecksumPolicy(); }
ChecksumPolicy extends AbstractPolicy implements PostDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( "resource".equals( request.getProperty( "filetype" ) ) ) { return; } if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown checksum policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( IGNORE.equals( policySetting ) ) { log.debug( "Checksum policy set to IGNORE." ); return; } if ( !localFile.exists() ) { throw new PolicyViolationException( "Checksum policy failure, local file " + localFile.getPath() + " does not exist to check." ); } if ( FAIL.equals( policySetting ) && localFile.isFileBased() ) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.isValidChecksums( algorithms ) ) { return; } for ( ChecksumAlgorithm algorithm : algorithms ) { Path file = checksum.getChecksumFile( algorithm ); try { Files.deleteIfExists( file ); } catch ( IOException e ) { log.error("Could not delete file {}", file); } } try { localFile.getStorage().removeAsset( localFile ); } catch ( IOException e ) { log.error("Could not delete file {}", localFile); } throw new PolicyViolationException( "Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file " + localFile.getPath() + "." ); } if ( FIX.equals( policySetting ) && localFile.isFileBased()) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.fixChecksums( algorithms ).getTotalStatus() != UpdateStatus.ERROR ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); return; } else { throw new PolicyViolationException( "Checksum policy set to FIX, " + "yet unable to update checksums for local file " + localFile.getPath() + "." ); } } throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting + "], please file a bug report." ); } ChecksumPolicy(); @Override void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ); @Override PolicyOption getDefaultOption(); @Override String getId(); @Override List<PolicyOption> getOptions(); }
ChecksumPolicy extends AbstractPolicy implements PostDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( "resource".equals( request.getProperty( "filetype" ) ) ) { return; } if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown checksum policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( IGNORE.equals( policySetting ) ) { log.debug( "Checksum policy set to IGNORE." ); return; } if ( !localFile.exists() ) { throw new PolicyViolationException( "Checksum policy failure, local file " + localFile.getPath() + " does not exist to check." ); } if ( FAIL.equals( policySetting ) && localFile.isFileBased() ) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.isValidChecksums( algorithms ) ) { return; } for ( ChecksumAlgorithm algorithm : algorithms ) { Path file = checksum.getChecksumFile( algorithm ); try { Files.deleteIfExists( file ); } catch ( IOException e ) { log.error("Could not delete file {}", file); } } try { localFile.getStorage().removeAsset( localFile ); } catch ( IOException e ) { log.error("Could not delete file {}", localFile); } throw new PolicyViolationException( "Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file " + localFile.getPath() + "." ); } if ( FIX.equals( policySetting ) && localFile.isFileBased()) { ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() ); if ( checksum.fixChecksums( algorithms ).getTotalStatus() != UpdateStatus.ERROR ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); return; } else { throw new PolicyViolationException( "Checksum policy set to FIX, " + "yet unable to update checksums for local file " + localFile.getPath() + "." ); } } throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting + "], please file a bug report." ); } ChecksumPolicy(); @Override void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ); @Override PolicyOption getDefaultOption(); @Override String getId(); @Override List<PolicyOption> getOptions(); static final ChecksumOption IGNORE; static final ChecksumOption FAIL; static final ChecksumOption FIX; }