{"record":{"id":"11ce41bfb5825db2","repo":"GoogleContainerTools/jib","slug":"no-or-multiple-layer-files-found-for-layer-hash-l","errorCode":null,"errorMessage":"No or multiple layer files found for layer hash <layerDigest> in directory: <layerDirectory>","messagePattern":"No or multiple layer files found for layer hash <layerDigest> in directory: <layerDirectory>","errorType":"exception","errorClass":"CacheCorruptedException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java","lineNumber":160,"sourceCode":"   * Retrieves the {@link CachedLayer} for the layer with digest {@code layerDigest}.\n   *\n   * @param layerDigest the layer digest\n   * @return the {@link CachedLayer} referenced by the layer digest, if found\n   * @throws CacheCorruptedException if the cache was found to be corrupted\n   * @throws IOException if an I/O exception occurs\n   */\n  Optional<CachedLayer> retrieve(DescriptorDigest layerDigest)\n      throws IOException, CacheCorruptedException {\n    Path layerDirectory = cacheStorageFiles.getLayerDirectory(layerDigest);\n    if (!Files.exists(layerDirectory)) {\n      return Optional.empty();\n    }\n\n    try (Stream<Path> files = Files.list(layerDirectory)) {\n      List<Path> layerFiles =\n          files.filter(CacheStorageFiles::isLayerFile).collect(Collectors.toList());\n      if (layerFiles.size() != 1) {\n        throw new CacheCorruptedException(\n            cacheStorageFiles.getCacheDirectory(),\n            \"No or multiple layer files found for layer hash \"\n                + layerDigest.getHash()\n                + \" in directory: \"\n                + layerDirectory);\n      }\n\n      Path layerFile = layerFiles.get(0);\n      return Optional.of(\n          CachedLayer.builder()\n              .setLayerDigest(layerDigest)\n              .setLayerSize(Files.size(layerFile))\n              .setLayerBlob(Blobs.from(layerFile))\n              .setLayerDiffId(cacheStorageFiles.getDigestFromFilename(layerFile))\n              .build());\n    }\n  }\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java#L142-L178","documentation":"Cached layers are stored one compressed layer file per digest directory. retrieve(layerDigest) lists the layer directory and requires exactly one layer file; zero files (missing layer) or more than one (duplicate) means the cache is inconsistent, and CacheCorruptedException is thrown naming the digest and directory.","triggerScenarios":"CacheStorageReader.retrieve() is called (during layer push/pull flows) and Files.list(layerDirectory) filtered by CacheStorageFiles::isLayerFile yields a count other than 1.","commonSituations":"Antivirus or cleanup tools deleting cache files, two Jib processes writing the same layer concurrently, partial download interrupted leaving zero/extra files, manually copying files into the cache.","solutions":["Delete the affected layer directory (or the whole cache) so the layer is re-fetched","Disable concurrent Jib builds sharing one cache directory, or give each a separate cache","Exclude the cache directory from antivirus scanning and cleanup jobs","Re-run the build after clearing ~/.cache/google-cloud-tools-java/jib"],"exampleFix":"// before: build fails on layer sha256:abc...\n// after: remove just that layer\nrm -rf ~/.cache/google-cloud-tools-java/jib/layers/sha256:abc...","handlingStrategy":"try-catch","validationCode":"long n = Files.list(layerDir).filter(Files::isRegularFile).count();\nif (n != 1) deleteRecursively(layerDir);","typeGuard":null,"tryCatchPattern":"try {\n  build();\n} catch (CacheCorruptedException e) {\n  String dir = extractLayerDir(e.getMessage());\n  if (dir != null) deleteRecursively(Path.of(dir)); else wipeCache();\n  build();\n}","preventionTips":["Serialize builds sharing a cache or use per-build caches","Add cache dir to AV exclusions","Never manually edit the layers directory"],"tags":["cache","filesystem","corruption"],"backgroundTag":"corrupted-cache-metadata","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}