提交 2ce23cbd 编写于 作者: W WangFengTu 提交者: lifeng68

register image to store

Signed-off-by: NWangFengTu <wangfengtu@huawei.com>
上级 65d17387
......@@ -31,6 +31,7 @@
#include "utils.h"
#include "sha256.h"
#include "path.h"
#include "libtar.h"
bool util_dir_exists(const char *path)
{
......
......@@ -59,6 +59,10 @@ char *util_file_digest(const char *filename);
char *util_full_file_digest(const char *filename);
int util_gzip_compressed(const char *filename, bool *gzip);
char *util_full_gzip_digest(const char *filename);
char *util_path_dir(const char *path);
char *util_add_path(const char *path, const char *name);
......
......@@ -78,8 +78,10 @@
#define OCI_MANIFEST_V1_JSON "application/vnd.oci.image.manifest.v1+json"
#define OCI_INDEX_V1_JSON "application/vnd.oci.image.index.v1+json"
#define DOCKER_IMAGE_LAYER_TAR_GZIP "application/vnd.docker.image.rootfs.diff.tar.gzip"
#define DOCKER_IMAGE_LAYER_FOREIGN_TAR_GZIP "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip"
#define DOCKER_IMAGE_V1 "application/vnd.docker.container.image.v1+json"
#define OCI_IMAGE_V1 "application/vnd.oci.image.config.v1+json"
#define OCI_IMAGE_LAYER_TAR_GZIP "application/vnd.oci.image.layer.v1.tar+gzip"
#endif
......@@ -39,6 +39,7 @@ int isula_pull_image(const im_pull_request *request, im_pull_response **response
}
options->image_name = util_strdup_s(request->image);
options->dest_image_name = util_strdup_s(request->image);
ret = registry_pull(options);
if (ret != 0) {
......
此差异已折叠。
......@@ -35,6 +35,7 @@ typedef struct {
registry_options comm_opt;
registry_auth auth;
char *image_name;
char *dest_image_name;
} registry_pull_options;
typedef struct {
......
......@@ -4,6 +4,8 @@
#include <stdint.h>
#include <time.h>
#include "types_def.h"
// 8 is enough for challenge, usually only one challenge is provided.
#define CHALLENGE_MAX 8
......@@ -29,9 +31,11 @@ typedef struct {
char *digest;
// Downloaded file path
char *file;
types_timestamp_t create_time;
} config_blob;
typedef struct {
bool empty_layer;
char *media_type;
// blob size
size_t size;
......@@ -44,11 +48,11 @@ typedef struct {
// Downloaded file path
char *file;
// already exist on local store
char *already_exist;
bool already_exist;
} layer_blob;
typedef struct {
char *full_name;
char *dest_image_name;
char *host;
char *name;
char *tag;
......
......@@ -55,6 +55,7 @@ static bool stream_check_error(void *stream, bool isgzip)
return true;
}
if (gzerr != NULL && strcmp(gzerr, "") != 0) {
ERROR("gzread error: %s", gzerr);
return true;
}
return false;
......@@ -283,7 +284,7 @@ char *sha256_digest_str(const char *val)
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
int ret = snprintf(output_buffer + (i * 2), 3, "%02x", (unsigned int)hash[i]);
if (ret >= 3 || ret < 0) {
return "";
return NULL;
}
}
output_buffer[SHA256_DIGEST_LENGTH * 2] = '\0';
......@@ -291,3 +292,84 @@ char *sha256_digest_str(const char *val)
return util_strdup_s(output_buffer);
}
char *sha256_digest_file(const char *filename, bool isgzip)
{
SHA256_CTX ctx;
unsigned char hash[SHA256_DIGEST_LENGTH] = { 0x00 };
char output_buffer[(SHA256_DIGEST_LENGTH * 2) + 1] = { 0x00 };
int i = 0;
char *buffer = NULL;
int n = 0;
int ret = 0;
void *stream = NULL;
if (filename == NULL) {
ERROR("Invalid NULL pointer");
return NULL;
}
if (isgzip) {
stream = (void*)gzopen(filename, "r");
} else {
stream = (void*)fopen(filename, "r");
}
if (stream == NULL) {
ERROR("open file %s failed: %s", filename, strerror(errno));
return NULL;
}
buffer = util_common_calloc_s(BLKSIZE);
if (buffer == NULL) {
ERROR("out of memory");
return NULL;
}
SHA256_Init(&ctx);
while (true) {
if (isgzip) {
n = gzread((gzFile)stream, buffer, BLKSIZE);
} else {
n = fread(buffer, 1, BLKSIZE, (FILE *)stream);
}
if (n <= 0) {
if (stream_check_error(stream, isgzip)) {
ret = -1;
goto out;
}
break;
}
if (n > 0) {
SHA256_Update(&ctx, buffer, n);
}
if (stream_check_eof(stream, isgzip)) {
break;
}
}
SHA256_Final(hash, &ctx);
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
int sret = snprintf(output_buffer + (i * 2), 3, "%02x", (unsigned int)hash[i]);
if (sret >= 3 || sret < 0) {
ERROR("snprintf failed when calc sha256 from file %s, result is %s", filename, sret);
return NULL;
}
}
output_buffer[SHA256_DIGEST_LENGTH * 2] = '\0';
out:
if (isgzip) {
gzclose((gzFile)stream);
} else {
fclose((FILE*)stream);
}
if (ret == 0) {
return util_strdup_s(output_buffer);
} else {
return NULL;
}
}
......@@ -42,6 +42,8 @@ extern int sha256sum_calculate(void *stream, char *buffer_out, size_t len,
The result is a 64 characters string without prefix "sha256:" */
char *sha256_digest(void *stream, bool isgzip);
char *sha256_digest_file(const char *filename, bool isgzip);
char *sha256_digest_str(const char *val);
# ifdef __cplusplus
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册