/** * Get the SHA1 from the {@link BlobAttributes} */ protected String getBlobSha1(final BlobAttributes blobAttributes) { BlobMetrics metrics = blobAttributes.getMetrics(); checkArgument(metrics != null, "Blob attributes are missing metrics"); String blobSha1 = metrics.getSha1Hash(); checkArgument(blobSha1 != null, "Blob metrics are missing SHA1 hash code"); return blobSha1; }
private void maybeUpdateAsset(final Repository repository, final Asset asset, final Blob blob) { Map<String, Object> packageJson = npmPackageParser.parsePackageJson(blob::getInputStream); NestedAttributesMap updatedMetadata = createFullPackageMetadata( new NestedAttributesMap("metadata", packageJson), repository.getName(), blob.getMetrics().getSha1Hash(), repository, extractPackageRootVersionUnlessEmpty); updatePackageRootIfShaIncorrect(repository, asset, blob, updatedMetadata, NpmPackageId.parse((String) packageJson.get(P_NAME)), (String) packageJson.get(P_VERSION)); }
@Override @Transactional public Component afterMove(final Component component, final Repository destination) { destination.optionalFacet(NpmHostedFacet.class).ifPresent(f -> { final StorageTx tx = UnitOfWork.currentTx(); tx.browseAssets(component).forEach(asset -> { Blob blob = checkNotNull(tx.getBlob(asset.blobRef())); final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(blob::getInputStream); final NpmPackageId packageId = NpmPackageId.parse((String) packageJson.get(P_NAME)); try { final NestedAttributesMap updatedMetadata = createFullPackageMetadata( new NestedAttributesMap("metadata", packageJson), destination.getName(), blob.getMetrics().getSha1Hash(), destination, extractNewestVersion); f.putPackageRoot(packageId, null, updatedMetadata); } catch (IOException e) { log.error("Failed to update package root, packageId: {}", packageId, e); } }); }); return component; } }
String oldBlobSha1 = oldBlob.getMetrics().getSha1Hash(); String newBlobSha1 = assetBlob.getBlob().getMetrics().getSha1Hash(); checksumsMatch = oldBlobSha1.equalsIgnoreCase(newBlobSha1);