From 51db6c626feef86435960c1be5510d31398fabfe Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Fri, 2 Jun 2023 17:20:04 +0800
Subject: [PATCH 04/15] fix inspect image by digest

Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
 .../oci/storage/image_store/image_store.c     | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c
index d89c28f4..aad8329e 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c
@@ -443,6 +443,27 @@ out:
     return value;
 }
 
+// by_digest returns the image which matches the specified name.
+static image_t *by_digest(const char *name)
+{
+    digest_image_t *digest_filter_images = NULL;
+    char *digest = NULL;
+    
+    // split digest for image name with digest
+    digest = strrchr(name, '@');
+    if (digest == NULL || util_reg_match(__DIGESTPattern, digest)) {
+        return NULL;
+    }
+    digest++;
+    digest_filter_images = (digest_image_t *)map_search(g_image_store->bydigest, (void *)digest);
+    if (digest_filter_images == NULL) {
+        return NULL;
+    }
+
+    // currently, a digest corresponds to an image, directly returning the first element
+    return linked_list_first_elem(&(digest_filter_images->images_list));
+}
+
 static image_t *lookup(const char *id)
 {
     image_t *value = NULL;
@@ -467,6 +488,12 @@ static image_t *lookup(const char *id)
         goto found;
     }
 
+    // get image by digest
+    value = by_digest(id);
+    if (value != NULL) {
+        goto found;
+    }
+
     return NULL;
 
 found:
-- 
2.25.1

