diff options
| author | Stefan Boberg <[email protected]> | 2023-09-20 15:22:03 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-20 15:22:03 +0200 |
| commit | 14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f (patch) | |
| tree | bf24ac15759385cea339f7e1cf5380f984f5699a /src/zen/cmds/vfs_cmd.cpp | |
| parent | changelog version bump (diff) | |
| download | archived-zen-14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f.tar.xz archived-zen-14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f.zip | |
VFS implementation for local storage service (#396)
currently, only Windows (using Projected File System) is supported
Diffstat (limited to 'src/zen/cmds/vfs_cmd.cpp')
| -rw-r--r-- | src/zen/cmds/vfs_cmd.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/zen/cmds/vfs_cmd.cpp b/src/zen/cmds/vfs_cmd.cpp new file mode 100644 index 000000000..4eb9b3195 --- /dev/null +++ b/src/zen/cmds/vfs_cmd.cpp @@ -0,0 +1,108 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "vfs_cmd.h" + +#include <zencore/compactbinarybuilder.h> +#include <zencore/fmtutils.h> +#include <zencore/logging.h> +#include <zencore/string.h> +#include <zencore/uid.h> +#include <zenhttp/formatters.h> +#include <zenhttp/httpclient.h> +#include <zenutil/zenserverprocess.h> + +namespace zen { + +using namespace std::literals; + +VfsCommand::VfsCommand() +{ + m_Options.add_option("", "", "verb", "VFS management verb (mount, unmount)", cxxopts::value(m_Verb), "<verb>"); + m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value(""), "<url>"); + m_Options.add_option("", "", "vfs-path", "Specify VFS mount point path", cxxopts::value(m_MountPath), "<path>"); + + m_Options.parse_positional({"verb", "vfs-path"}); +} + +VfsCommand::~VfsCommand() +{ +} + +int +VfsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions, argc, argv); + + if (!ZenCmdBase::ParseOptions(argc, argv)) + { + return 0; + } + + // Validate arguments + + m_HostName = ResolveTargetHostSpec(m_HostName); + + if (m_HostName.empty()) + throw OptionParseException("unable to resolve server specification"); + + HttpClient Http(m_HostName); + + if (m_Verb == "mount"sv) + { + if (m_MountPath.empty()) + throw OptionParseException("No source specified"); + + CbObjectWriter Cbo; + Cbo << "method" + << "mount"; + + Cbo.BeginObject("params"); + Cbo << "path" << m_MountPath; + Cbo.EndObject(); + + if (HttpClient::Response Result = Http.Post("/vfs"sv, Cbo.Save())) + { + } + else + { + Result.ThrowError("VFS mount request failed"sv); + + return 1; + } + } + else if (m_Verb == "unmount"sv) + { + CbObjectWriter Cbo; + Cbo << "method" + << "unmount"; + + if (HttpClient::Response Result = Http.Post("/vfs"sv, Cbo.Save())) + { + } + else + { + Result.ThrowError("VFS unmount request failed"sv); + + return 1; + } + } + else if (m_Verb == "info"sv) + { + if (HttpClient::Response Result = Http.Get(fmt::format("/vfs/info"))) + { + ExtendableStringBuilder<256> Json; + Result.AsObject().ToJson(Json); + ZEN_CONSOLE("{}", Json); + } + else + { + Result.ThrowError("VFS info fetch failed"sv); + + return 1; + } + } + + return 0; +} + +} // namespace zen |