Commit 7a7f2cd1 authored by Ramon Nou's avatar Ramon Nou Committed by Marc Vef
Browse files

Reformat util/integration/gkfs.io files

parent 554f0e2c
Loading
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@
namespace io {

struct buffer {
    buffer(::size_t size = 0) :
        m_data(size) { }
    buffer(::size_t size = 0) : m_data(size) {}

    buffer(nullptr_t p) {}

@@ -63,13 +62,11 @@ struct buffer {
};

inline void
to_json(nlohmann::json& record, 
        const buffer& out) {
to_json(nlohmann::json& record, const buffer& out) {

    if(out == nullptr) {
        record = nullptr;
    }
    else {
    } else {

        //    record = fmt::format("x{:2x}", fmt::join(out, "x"));
        record = out.storage();
+14 −30
Original line number Diff line number Diff line
@@ -29,25 +29,20 @@ struct chdir_options {
    bool verbose{};
    std::string pathname;

    REFL_DECL_STRUCT(chdir_options,
        REFL_DECL_MEMBER(bool, verbose),
        REFL_DECL_MEMBER(std::string, pathname)
    );
    REFL_DECL_STRUCT(chdir_options, REFL_DECL_MEMBER(bool, verbose),
                     REFL_DECL_MEMBER(std::string, pathname));
};

struct chdir_output {
    int retval;
    int errnum;

    REFL_DECL_STRUCT(chdir_output,
        REFL_DECL_MEMBER(int, retval),
        REFL_DECL_MEMBER(int, errnum)
    );
    REFL_DECL_STRUCT(chdir_output, REFL_DECL_MEMBER(int, retval),
                     REFL_DECL_MEMBER(int, errnum));
};

void
to_json(json& record,
        const chdir_output& out) {
to_json(json& record, const chdir_output& out) {
    record = serialize(out);
}

@@ -71,26 +66,15 @@ chdir_init(CLI::App& app) {

    // Create the option and subcommand objects
    auto opts = std::make_shared<chdir_options>();
    auto* cmd = app.add_subcommand(
            "chdir",
            "Execute the chdir() system call");
    auto* cmd = app.add_subcommand("chdir", "Execute the chdir() system call");

    // Add options to cmd, binding them to opts
    cmd->add_flag(
            "-v,--verbose",
            opts->verbose,
            "Produce human readable output"
        );

    cmd->add_option(
            "pathname",
            opts->pathname,
            "Directory name"
        )
    cmd->add_flag("-v,--verbose", opts->verbose,
                  "Produce human readable output");

    cmd->add_option("pathname", opts->pathname, "Directory name")
            ->required()
            ->type_name("");

    cmd->callback([opts]() {
        chdir_exec(*opts);
    });
    cmd->callback([opts]() { chdir_exec(*opts); });
}
+3 −1
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
#define IO_COMMANDS_HPP

// forward declare CLI::App
namespace CLI { struct App; }
namespace CLI {
struct App;
}

void
mkdir_init(CLI::App& app);
+26 −41
Original line number Diff line number Diff line
@@ -29,10 +29,8 @@ struct getcwd_validate_options {
    bool verbose{};
    std::string pathname;

    REFL_DECL_STRUCT(getcwd_validate_options,
        REFL_DECL_MEMBER(bool, verbose),
        REFL_DECL_MEMBER(std::string, pathname)
    );
    REFL_DECL_STRUCT(getcwd_validate_options, REFL_DECL_MEMBER(bool, verbose),
                     REFL_DECL_MEMBER(std::string, pathname));
};

struct getcwd_validate_output {
@@ -40,16 +38,13 @@ struct getcwd_validate_output {
    std::string path;
    int errnum;

    REFL_DECL_STRUCT(getcwd_validate_output,
        REFL_DECL_MEMBER(int, retval),
    REFL_DECL_STRUCT(getcwd_validate_output, REFL_DECL_MEMBER(int, retval),
                     REFL_DECL_MEMBER(std::string, path),
        REFL_DECL_MEMBER(int, errnum)
    );
                     REFL_DECL_MEMBER(int, errnum));
};

void
to_json(json& record,
        const getcwd_validate_output& out) {
to_json(json& record, const getcwd_validate_output& out) {
    record = serialize(out);
}

@@ -57,7 +52,6 @@ void
getcwd_validate_exec(const getcwd_validate_options& opts) {



    char path[1024];
    auto rv = ::chdir(opts.pathname.c_str());
    if(rv == 0) {
@@ -70,7 +64,8 @@ getcwd_validate_exec(const getcwd_validate_options& opts) {

        if(path == opts.pathname)
            if(opts.verbose) {
            fmt::print("getcwd_validate(pathname=\"{}\") = {}, errno: {} [{}]\n",
                fmt::print(
                        "getcwd_validate(pathname=\"{}\") = {}, errno: {} [{}]\n",
                        opts.pathname, cwd, errno, ::strerror(errno));
                return;
            }
@@ -85,26 +80,16 @@ getcwd_validate_init(CLI::App& app) {

    // Create the option and subcommand objects
    auto opts = std::make_shared<getcwd_validate_options>();
    auto* cmd = app.add_subcommand(
            "getcwd_validate",
    auto* cmd = app.add_subcommand("getcwd_validate",
                                   "Execute the getcwd_validate() system call");

    // Add options to cmd, binding them to opts
    cmd->add_flag(
            "-v,--verbose",
            opts->verbose,
            "Produce human readable output"
        );

     cmd->add_option(
            "pathname",
            opts->pathname,
            "Directory name"
        )
    cmd->add_flag("-v,--verbose", opts->verbose,
                  "Produce human readable output");

    cmd->add_option("pathname", opts->pathname, "Directory name")
            ->required()
            ->type_name("");

    cmd->callback([opts]() {
        getcwd_validate_exec(*opts);
    });
    cmd->callback([opts]() { getcwd_validate_exec(*opts); });
}
+42 −62
Original line number Diff line number Diff line
@@ -30,42 +30,41 @@
using json = nlohmann::json;

struct lseek_options {
    bool verbose;
    bool verbose{};
    std::string pathname;
    ::off_t offset;
    int whence;

    REFL_DECL_STRUCT(lseek_options,
        REFL_DECL_MEMBER(bool, verbose),
    REFL_DECL_STRUCT(lseek_options, REFL_DECL_MEMBER(bool, verbose),
                     REFL_DECL_MEMBER(std::string, pathname),
                     REFL_DECL_MEMBER(::off_t, offset),
        REFL_DECL_MEMBER(int, whence)
    );
                     REFL_DECL_MEMBER(int, whence));
};

struct lseek_output {
    ::off_t retval;
    int errnum;

    REFL_DECL_STRUCT(lseek_output,
        REFL_DECL_MEMBER(::off_t, retval),
        REFL_DECL_MEMBER(int, errnum)
    );
    REFL_DECL_STRUCT(lseek_output, REFL_DECL_MEMBER(::off_t, retval),
                     REFL_DECL_MEMBER(int, errnum));
};

void
to_json(json& record, 
        const lseek_output& out) {
to_json(json& record, const lseek_output& out) {
    record = serialize(out);
}

std::string
whence2str(int whence) {
    switch(whence) {
       case SEEK_SET : return "SEEK_SET";
       case SEEK_CUR : return "SEEK_CUR";
       case SEEK_END : return "SEEK_END";
       default : return "UNKNOWN";
        case SEEK_SET:
            return "SEEK_SET";
        case SEEK_CUR:
            return "SEEK_CUR";
        case SEEK_END:
            return "SEEK_END";
        default:
            return "UNKNOWN";
    }
    return "UNKNOWN";
}
@@ -91,8 +90,10 @@ lseek_exec(const lseek_options& opts) {
    int rv = ::lseek(fd, opts.offset, opts.whence);

    if(opts.verbose) {
        fmt::print("lseek(pathname=\"{}\", offset='{}', whence='{}') = {}, errno: {} [{}]\n", 
                   opts.pathname, opts.offset, whence2str(opts.whence), rv, errno, ::strerror(errno));
        fmt::print(
                "lseek(pathname=\"{}\", offset='{}', whence='{}') = {}, errno: {} [{}]\n",
                opts.pathname, opts.offset, whence2str(opts.whence), rv, errno,
                ::strerror(errno));
        return;
    }

@@ -105,44 +106,23 @@ lseek_init(CLI::App& app) {

    // Create the option and subcommand objects
    auto opts = std::make_shared<lseek_options>();
    auto* cmd = app.add_subcommand(
            "lseek", 
            "Execute the lseek() system call");
    auto* cmd = app.add_subcommand("lseek", "Execute the lseek() system call");

    // Add options to cmd, binding them to opts
    cmd->add_flag(
            "-v,--verbose",
            opts->verbose,
            "Produce human writeable output"
        );

    cmd->add_option(
            "pathname", 
            opts->pathname,
            "Directory name"
        )
    cmd->add_flag("-v,--verbose", opts->verbose,
                  "Produce human writeable output");

    cmd->add_option("pathname", opts->pathname, "Directory name")
            ->required()
            ->type_name("");

    cmd->add_option(
            "offset", 
            opts->offset,
            "offset used"
        )
    cmd->add_option("offset", opts->offset, "offset used")
            ->required()
            ->type_name("");

    cmd->add_option(
            "whence", 
            opts->whence,
            "Whence the action is done"
        )
    cmd->add_option("whence", opts->whence, "Whence the action is done")
            ->required()
            ->type_name("");

    cmd->callback([opts]() { 
        lseek_exec(*opts); 
    });
    cmd->callback([opts]() { lseek_exec(*opts); });
}

Loading