Merge branch '3.2.x'

Closes gh-40799
This commit is contained in:
Scott Frederick
2024-05-16 17:38:07 -05:00
5 changed files with 26 additions and 14 deletions

View File

@@ -102,6 +102,17 @@ public abstract class AbstractBuildLog implements BuildLog {
log();
}
@Override
public void failedCleaningWorkDir(Cache cache, Exception exception) {
StringBuilder message = new StringBuilder("Warning: Working location " + cache + " could not be cleaned");
if (exception != null) {
message.append(": ").append(exception.getMessage());
}
log();
log(message.toString());
log();
}
private String getDigest(Image image) {
List<String> digests = image.getDigests();
return (digests.isEmpty() ? "" : digests.get(0));

View File

@@ -114,6 +114,13 @@ public interface BuildLog {
*/
void taggedImage(ImageReference tag);
/**
* Log that a cache cleanup step was not completed successfully.
* @param cache the cache
* @param exception any exception that caused the failure
*/
void failedCleaningWorkDir(Cache cache, Exception exception);
/**
* Factory method that returns a {@link BuildLog} the outputs to {@link System#out}.
* @return a build log instance that logs to system out

View File

@@ -311,7 +311,7 @@ class Lifecycle implements Closeable {
deleteVolume(cache.getVolume().getVolumeName());
}
if (cache.getBind() != null) {
deleteBind(cache.getBind().getSource());
deleteBind(cache.getBind());
}
}
@@ -319,12 +319,12 @@ class Lifecycle implements Closeable {
this.docker.volume().delete(name, true);
}
private void deleteBind(String source) {
private void deleteBind(Cache.Bind bind) {
try {
FileSystemUtils.deleteRecursively(Path.of(source));
FileSystemUtils.deleteRecursively(Path.of(bind.getSource()));
}
catch (IOException ex) {
throw new IllegalStateException("Error cleaning bind mount directory '" + source + "'", ex);
this.log.failedCleaningWorkDir(bind, ex);
}
}