Skip to content

com.github.dockerjava.api.model.PullResponseItem#isPullSuccessIndicated fails to check for "Exists" status #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AndyGee opened this issue Nov 22, 2022 · 7 comments · Fixed by #2335

Comments

@AndyGee
Copy link

AndyGee commented Nov 22, 2022

com.github.dockerjava.api.model.PullResponseItem#isPullSuccessIndicated checks for several success states, but misses "Exists" and treats this status as a failure.

Caused by: com.github.dockerjava.api.exception.DockerClientException: Could not pull image: Exists

If would be great if the success status codes could be a configurable list that the library user could append to.

@AndyGee
Copy link
Author

AndyGee commented Nov 22, 2022

Quick fix was to create this class in my test classpath:

package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Represents a pull response stream item
 */
public class PullResponseItem extends com.github.dockerjava.api.model.ResponseItem {

  private static final long serialVersionUID = -2575482839766823293L;

  private static final String LEGACY_REGISTRY = "this image was pulled from a legacy registry";

  private static final String DOWNLOADED_NEWER_IMAGE = "Downloaded newer image";

  private static final String IMAGE_UP_TO_DATE = "Image is up to date";

  private static final String DOWNLOAD_COMPLETE = "Download complete";

  private static final String DOWNLOADED_SWARM = ": downloaded";

  private static final String EXISTS = "Exists";

  /**
   * Returns whether the status indicates a successful pull operation
   *
   * @returns true: status indicates that pull was successful, false: status doesn't indicate a successful pull
   */
  @JsonIgnore
  public boolean isPullSuccessIndicated() {
    if (isErrorIndicated() || getStatus() == null) {
      return false;
    }

    return (
      getStatus().contains(DOWNLOAD_COMPLETE)
        || getStatus().contains(IMAGE_UP_TO_DATE)
        || getStatus().contains(DOWNLOADED_NEWER_IMAGE)
        || getStatus().contains(LEGACY_REGISTRY)
        || getStatus().contains(DOWNLOADED_SWARM)
        || getStatus().contains(EXISTS));
  }
}

@eddumelendez
Copy link
Member

@AndyGee thanks for reporting this issue! is the full status Already exists? I look at moby and just found that one.

@AndyGee
Copy link
Author

AndyGee commented Jan 23, 2023

@eddumelendez Sorry for the late reply. On Win at least, it is "Exists" - However, I'm currently using the above workaround in all our projects, which are also built on ios and ubuntu based systems.

@AndyGee
Copy link
Author

AndyGee commented Jan 23, 2023

@eddumelendez another workaround is of course to delete the image, but that's kind of drastic ;-) - Interestingly the IMAGE_UP_TO_DATE is not the status here, which is what I'd expect given that the image is actually up to date.

@AndyGee
Copy link
Author

AndyGee commented Jan 23, 2023

image

@stale
Copy link

stale bot commented Apr 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Aug 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants