Skip to content

Commit

Permalink
Alternative: try retrieving layer (redundantly) instead of just check…
Browse files Browse the repository at this point in the history
…ing for layer directory presence
  • Loading branch information
emmileaf committed Sep 2, 2022
1 parent 755dcfc commit b231d79
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,18 @@ boolean allLayersCached(ManifestTemplate manifest) {
}

for (DescriptorDigest layerDigest : layerDigests) {
Path layerDirectory = cacheStorageFiles.getLayerDirectory(layerDigest);
if (!Files.exists(layerDirectory)) {
// Path layerDirectory = cacheStorageFiles.getLayerDirectory(layerDigest);
// if (!Files.exists(layerDirectory)) {
// return false;
// }

Optional<CachedLayer> optionalCachedLayer;
try {
optionalCachedLayer = retrieve(layerDigest);
} catch (Exception ex) {
return false;
}
if (!optionalCachedLayer.isPresent()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,15 +654,23 @@ public void testAllLayersCached_v21SingleManifest()
new ManifestAndConfigTemplate(manifest, new ContainerConfigurationTemplate());

// Create only one of the layer directories.
DescriptorDigest firstlayerDigest =
DescriptorDigest firstLayerDigest =
DescriptorDigest.fromHash(manifest.getLayerDigests().get(0).getHash());
Files.createDirectories(cacheStorageFiles.getLayerDirectory(firstlayerDigest));
Files.createDirectories(cacheStorageFiles.getLayerDirectory(firstLayerDigest));
try (OutputStream out =
Files.newOutputStream(cacheStorageFiles.getLayerFile(firstLayerDigest, layerDigest2))) {
out.write("layerBlob".getBytes(StandardCharsets.UTF_8));
}
Assert.assertFalse(cacheStorageReader.allLayersCached(manifestAndConfig.getManifest()));

// Create the other layer directory.
DescriptorDigest secondlayerDigest =
DescriptorDigest secondLayerDigest =
DescriptorDigest.fromHash(manifest.getLayerDigests().get(1).getHash());
Files.createDirectories(cacheStorageFiles.getLayerDirectory(secondlayerDigest));
Files.createDirectories(cacheStorageFiles.getLayerDirectory(secondLayerDigest));
try (OutputStream out =
Files.newOutputStream(cacheStorageFiles.getLayerFile(secondLayerDigest, layerDigest2))) {
out.write("layerBlob".getBytes(StandardCharsets.UTF_8));
}
Assert.assertTrue(cacheStorageReader.allLayersCached(manifestAndConfig.getManifest()));
}

Expand All @@ -683,7 +691,12 @@ public void testAllLayersCached_v22SingleManifest()
Assert.assertFalse(cacheStorageReader.allLayersCached(manifestAndConfig.getManifest()));
// Create the layer directory.
DescriptorDigest layerDigest = manifest.getLayers().get(0).getDigest();
manifest.getLayers().get(0);
Files.createDirectories(cacheStorageFiles.getLayerDirectory(layerDigest));
try (OutputStream out =
Files.newOutputStream(cacheStorageFiles.getLayerFile(layerDigest, layerDigest2))) {
out.write("layerBlob".getBytes(StandardCharsets.UTF_8));
}
Assert.assertTrue(cacheStorageReader.allLayersCached(manifestAndConfig.getManifest()));
}
}

0 comments on commit b231d79

Please sign in to comment.