Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
add json files for json parsing capability
Browse files Browse the repository at this point in the history
  • Loading branch information
kchilleri committed Apr 30, 2024
1 parent 3033595 commit a1f6dd7
Show file tree
Hide file tree
Showing 5 changed files with 1,355 additions and 11 deletions.
13 changes: 6 additions & 7 deletions bin/ch-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "config.h"
#include "ch_core.h"
#include "ch_misc.h"

#include "json.h"

/** Constants and macros **/

Expand Down Expand Up @@ -208,6 +208,11 @@ int main(int argc, char *argv[])
Tf (!args.c.writable || args.unsafe,
"--write invalid when running by name");
break;
case IMG_OCI_BUNDLE:
/* Parse config.json file -> containerize */
/* OR call ch-run-oci to create and start/run container */
args.c.newroot = path_join(args.c.img_ref, "/rootfs");
break;
case IMG_SQUASH:
#ifndef HAVE_LIBSQUASHFUSE
FATAL("this ch-run does not support internal SquashFS mounts");
Expand All @@ -216,12 +221,6 @@ int main(int argc, char *argv[])
case IMG_NONE:
FATAL("unknown image type: %s", args.c.img_ref);
break;
case OCI_BUNDLE:
if (args.c.newroot != NULL) // --mount was set
WARNING("--mount invalid with directory image, ignoring");
args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false);
img_directory_verify(args.c.newroot, &args);
break;
}

if (args.c.join) {
Expand Down
6 changes: 3 additions & 3 deletions bin/ch_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ enum img_type image_type(const char *ref, const char *storage_dir)
struct stat st;
FILE *fp;
char magic[4]; // four bytes, not a string
char *conff = cat(ref, "/config.json");
char *rootfs = cat(ref, "/rootfs");
char *conff = path_join(ref, "/config.json");
char *rootfs = path_join(ref, "/rootfs");

// If there’s a directory in storage where we would expect there to be if
// ref were an image name, assume it really is an image name.
Expand All @@ -386,7 +386,7 @@ enum img_type image_type(const char *ref, const char *storage_dir)
// and config.json file, assume it is an oci bundle
if (S_ISDIR(st.st_mode)) {
if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) {
return OCI_BUNDLE;
return IMG_OCI_BUNDLE;
} else {
return IMG_DIRECTORY;
}
Expand Down
2 changes: 1 addition & 1 deletion bin/ch_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum img_type {
IMG_SQUASH, // SquashFS archive file (not yet mounted)
IMG_NAME, // name of image in storage
IMG_NONE, // image type is not set yet
OCI_BUNDLE, // contains rootfs img_directory and config.json file
IMG_OCI_BUNDLE, // contains rootfs img_directory and config.json file
};

struct container {
Expand Down
Loading

0 comments on commit a1f6dd7

Please sign in to comment.