archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java
/**
     * Writes a checksum file, if it does not exist or if it exists and has a different
     * checksum value.
     *
     * @param algorithms the hashes to check for.
     * @return true if checksums were created successfully.
     */
Writes a checksum file, if it does not exist or if it exists and has a different
checksum value.

@param algorithms the hashes to check for.
@return true if checksums were created successfully.
Writes a checksum file if it does not exist or if it exists and has a different checksum value . @param algorithms the hashes to check for . @return true if checksums were created successfully .
public UpdateStatusList fixChecksums( List<ChecksumAlgorithm> algorithms )
    {
        UpdateStatusList result = UpdateStatusList.INITIALIZE(algorithms);
        List<Checksum> checksums;
        try
        {
            checksums = ChecksumUtil.initializeChecksums(getReferenceFile(), algorithms);
        }
        catch (IOException e )
        {
            log.warn( e.getMessage( ), e );
            result.setTotalError(e);
            return result;
        }
        if ( checksums.isEmpty( ) )
        {
            return result;
        }
        boolean valid = true;
        for ( Checksum checksum : checksums )
        {
            ChecksumAlgorithm checksumAlgorithm = checksum.getAlgorithm( );
            try
            {
                Path checksumFile = getChecksumFile( checksumAlgorithm );
                if ( Files.exists( checksumFile ) )
                {
                    String expectedChecksum;
                    try
                    {
                        expectedChecksum = parseChecksum( checksumFile, checksumAlgorithm, referenceFile.getFileName( ).toString( ), FILE_ENCODING );
                    } catch (ChecksumValidationException ex) {
                        expectedChecksum = "";
                    }
                    if ( !checksum.compare( expectedChecksum ) )
                    {
                        writeChecksumFile( checksumFile, FILE_ENCODING, checksum.getChecksum( ) );
                        result.setStatus(checksumAlgorithm,UpdateStatus.UPDATED);
                    }
                }
                else
                {
                    writeChecksumFile( checksumFile, FILE_ENCODING, checksum.getChecksum( ) );
                    result.setStatus(checksumAlgorithm, UpdateStatus.CREATED);
                }
            }
            catch ( ChecksumValidationException e )
            {
                log.warn( e.getMessage( ), e );
                result.setErrorStatus(checksumAlgorithm, e);
            }
        }
        return result;
    }
public UpdateStatusList fixChecksums ( List < ChecksumAlgorithm > algorithms ) { UpdateStatusList result = UpdateStatusList . INITIALIZE ( algorithms ) ; List < Checksum > checksums ; try { checksums = ChecksumUtil . initializeChecksums ( getReferenceFile ( ) , algorithms ) ; } catch ( IOException e ) { log . warn ( e . getMessage ( ) , e ) ; result . setTotalError ( e ) ; return result ; } if ( checksums . isEmpty ( ) ) { return result ; } boolean valid = true ; for ( Checksum checksum : checksums ) { ChecksumAlgorithm checksumAlgorithm = checksum . getAlgorithm ( ) ; try { Path checksumFile = getChecksumFile ( checksumAlgorithm ) ; if ( Files . exists ( checksumFile ) ) { String expectedChecksum ; try { expectedChecksum = parseChecksum ( checksumFile , checksumAlgorithm , referenceFile . getFileName ( ) . toString ( ) , FILE_ENCODING ) ; } catch ( ChecksumValidationException ex ) { expectedChecksum = "" ; } if ( ! checksum . compare ( expectedChecksum ) ) { writeChecksumFile ( checksumFile , FILE_ENCODING , checksum . getChecksum ( ) ) ; result . setStatus ( checksumAlgorithm , UpdateStatus . UPDATED ) ; } } else { writeChecksumFile ( checksumFile , FILE_ENCODING , checksum . getChecksum ( ) ) ; result . setStatus ( checksumAlgorithm , UpdateStatus . CREATED ) ; } } catch ( ChecksumValidationException e ) { log . warn ( e . getMessage ( ) , e ) ; result . setErrorStatus ( checksumAlgorithm , e ) ; } } return result ; }
Writes a checksum file, if it does not exist or if it exists and has a different
 checksum value.
Writes a checksum file if it does not exist or if it exists and has a different checksum value .
// Parse file once, for all checksums. // Any checksums? // No checksum objects, no checksum files, default to is valid. // check the hash files // overwrite checksum file