diff options
| author | Stefan Boberg <[email protected]> | 2026-04-20 13:14:54 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-04-20 13:14:54 +0200 |
| commit | aed68370f182b31efd9dce116ab1c9d33ebc35cb (patch) | |
| tree | 4db1f02440bf142ad1a8e3812895efd294a6c52a | |
| parent | added support for trace regions (#984) (diff) | |
| download | archived-zen-aed68370f182b31efd9dce116ab1c9d33ebc35cb.tar.xz archived-zen-aed68370f182b31efd9dce116ab1c9d33ebc35cb.zip | |
zen: remove unused 'copy' and 'run' subcommands (#986)
These CLI commands are no longer useful and have been dropped from the zen client.
| -rw-r--r-- | src/zen/cmds/copy_cmd.cpp | 207 | ||||
| -rw-r--r-- | src/zen/cmds/copy_cmd.h | 32 | ||||
| -rw-r--r-- | src/zen/cmds/run_cmd.cpp | 194 | ||||
| -rw-r--r-- | src/zen/cmds/run_cmd.h | 30 | ||||
| -rw-r--r-- | src/zen/zen.cpp | 6 |
5 files changed, 0 insertions, 469 deletions
diff --git a/src/zen/cmds/copy_cmd.cpp b/src/zen/cmds/copy_cmd.cpp deleted file mode 100644 index 530661607..000000000 --- a/src/zen/cmds/copy_cmd.cpp +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "copy_cmd.h" - -#include <zencore/filesystem.h> -#include <zencore/fmtutils.h> -#include <zencore/logging.h> -#include <zencore/string.h> -#include <zencore/timer.h> - -namespace zen { - -CopyCommand::CopyCommand() -{ - m_Options.add_options()("h,help", "Print help"); - m_Options.add_options()("no-clone", "Do not perform block clone", cxxopts::value(m_NoClone)->default_value("false")); - m_Options.add_options()("must-clone", - "Always perform block clone (fails if clone is not possible)", - cxxopts::value(m_MustClone)->default_value("false")); - m_Options.add_option("", "s", "source", "Copy source", cxxopts::value(m_CopySource), "<file/directory>"); - m_Options.add_option("", "t", "target", "Copy target", cxxopts::value(m_CopyTarget), "<file/directory>"); - m_Options.parse_positional({"source", "target"}); -} - -CopyCommand::~CopyCommand() = default; - -void -CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) -{ - ZEN_UNUSED(GlobalOptions); - - if (!ParseOptions(argc, argv)) - { - return; - } - - // Validate arguments - - if (m_CopySource.empty()) - throw OptionParseException("'--source' is required", m_Options.help()); - - if (m_CopyTarget.empty()) - throw OptionParseException("'--target' is required", m_Options.help()); - - std::filesystem::path FromPath = m_CopySource; - std::filesystem::path ToPath = m_CopyTarget; - - std::error_code Ec; - std::filesystem::path FromCanonical = std::filesystem::canonical(FromPath, Ec); - - if (!Ec) - { - std::filesystem::path ToCanonical = std::filesystem::canonical(ToPath, Ec); - - if (!Ec) - { - if (FromCanonical == ToCanonical) - { - throw std::runtime_error("Target and source must be distinct files or directories"); - } - } - } - - const bool IsFileCopy = IsFile(m_CopySource); - const bool IsDirCopy = IsDir(m_CopySource); - - if (!IsFileCopy && !IsDirCopy) - { - throw std::runtime_error("Invalid source specification (neither directory nor file)"); - } - - if (IsFileCopy && IsDirCopy) - { - throw std::runtime_error("Invalid source specification (both directory AND file!?)"); - } - - if (IsDirCopy) - { - if (IsFile(ToPath)) - { - throw std::runtime_error("Attempted copy of directory into file"); - } - - if (!IsDir(ToPath)) - { - CreateDirectories(ToPath); - } - - std::filesystem::path ToCanonical = std::filesystem::canonical(ToPath, Ec); - - if (!Ec) - { - if (ToCanonical.generic_string().starts_with(FromCanonical.generic_string()) || - FromCanonical.generic_string().starts_with(ToCanonical.generic_string())) - { - throw std::runtime_error("Invalid parent/child relationship for source/target directories"); - } - } - - // Multi file copy - - ZEN_CONSOLE("copying {} -> {}", FromPath, ToPath); - - zen::Stopwatch Timer; - - struct CopyVisitor : public FileSystemTraversal::TreeVisitor - { - CopyVisitor(std::filesystem::path InBasePath, zen::CopyFileOptions InCopyOptions) - : BasePath(InBasePath) - , CopyOptions(InCopyOptions) - { - } - - virtual void VisitFile(const std::filesystem::path& Parent, - const path_view& File, - uint64_t FileSize, - uint32_t, - uint64_t) override - { - ZEN_UNUSED(FileSize); - std::error_code Ec; - const std::filesystem::path Relative = std::filesystem::relative(Parent, BasePath, Ec); - - if (Ec) - { - FailedFileCount++; - } - else - { - const std::filesystem::path FromPath = Parent / File; - const std::filesystem::path ToPath = TargetPath / Relative / File; - - try - { - zen::CreateDirectories(TargetPath / Relative); - if (zen::CopyFile(FromPath, ToPath, CopyOptions)) - { - ++FileCount; - ByteCount += FileSize; - } - else - { - throw std::logic_error("CopyFile failed in an unexpected way"); - } - } - catch (const std::exception& Ex) - { - ++FailedFileCount; - - ZEN_CONSOLE_ERROR("Failed to copy '{}' to '{}': '{}'", FromPath, ToPath, Ex.what()); - } - } - } - - virtual bool VisitDirectory(const std::filesystem::path&, const path_view&, uint32_t) override { return true; } - - std::filesystem::path BasePath; - std::filesystem::path TargetPath; - zen::CopyFileOptions CopyOptions; - int FileCount = 0; - uint64_t ByteCount = 0; - int FailedFileCount = 0; - }; - - zen::CopyFileOptions CopyOptions; - CopyOptions.EnableClone = !m_NoClone; - CopyOptions.MustClone = m_MustClone; - - CopyVisitor Visitor{FromPath, CopyOptions}; - Visitor.TargetPath = ToPath; - - FileSystemTraversal Traversal; - Traversal.TraverseFileSystem(FromPath, Visitor); - - ZEN_CONSOLE("Copy of {} files ({}) completed in {} ({})", - Visitor.FileCount, - NiceBytes(Visitor.ByteCount), - zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()), - zen::NiceRate(Visitor.ByteCount, (uint32_t)Timer.GetElapsedTimeMs())); - - if (Visitor.FailedFileCount) - { - throw std::runtime_error(fmt::format("{} file copy operations FAILED", Visitor.FailedFileCount)); - } - } - else - { - // Single file copy - - zen::Stopwatch Timer; - - zen::CopyFileOptions CopyOptions; - CopyOptions.EnableClone = !m_NoClone; - - zen::CreateDirectories(ToPath.parent_path()); - if (zen::CopyFile(FromPath, ToPath, CopyOptions)) - { - ZEN_CONSOLE("Copy completed in {}", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs())); - } - else - { - throw std::runtime_error(fmt::format("Failed to copy '{}' to '{}'", FromPath, ToPath)); - } - } -} - -} // namespace zen diff --git a/src/zen/cmds/copy_cmd.h b/src/zen/cmds/copy_cmd.h deleted file mode 100644 index 757a8e691..000000000 --- a/src/zen/cmds/copy_cmd.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "../zen.h" - -namespace zen { - -/** Copy files, possibly using block cloning - */ -class CopyCommand : public ZenCmdBase -{ -public: - static constexpr char Name[] = "copy"; - static constexpr char Description[] = "Copy file(s)"; - - CopyCommand(); - ~CopyCommand(); - - virtual cxxopts::Options& Options() override { return m_Options; } - virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override; - virtual ZenCmdCategory& CommandCategory() const override { return g_UtilitiesCategory; } - -private: - cxxopts::Options m_Options{Name, Description}; - std::filesystem::path m_CopySource; - std::filesystem::path m_CopyTarget; - bool m_NoClone = false; - bool m_MustClone = false; -}; - -} // namespace zen diff --git a/src/zen/cmds/run_cmd.cpp b/src/zen/cmds/run_cmd.cpp deleted file mode 100644 index ee47eb9f3..000000000 --- a/src/zen/cmds/run_cmd.cpp +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "run_cmd.h" - -#include <zencore/filesystem.h> -#include <zencore/fmtutils.h> -#include <zencore/logging.h> -#include <zencore/process.h> -#include <zencore/string.h> -#include <zencore/timer.h> - -using namespace std::literals; - -#define ZEN_COLOR_BLACK "\033[0;30m" -#define ZEN_COLOR_RED "\033[0;31m" -#define ZEN_COLOR_GREEN "\033[0;32m" -#define ZEN_COLOR_YELLOW "\033[0;33m" -#define ZEN_COLOR_BLUE "\033[0;34m" -#define ZEN_COLOR_MAGENTA "\033[0;35m" -#define ZEN_COLOR_CYAN "\033[0;36m" -#define ZEN_COLOR_WHITE "\033[0;37m" - -#define ZEN_BRIGHT_COLOR_BLACK "\033[1;30m" -#define ZEN_BRIGHT_COLOR_RED "\033[1;31m" -#define ZEN_BRIGHT_COLOR_GREEN "\033[1;32m" -#define ZEN_BRIGHT_COLOR_YELLOW "\033[1;33m" -#define ZEN_BRIGHT_COLOR_BLUE "\033[1;34m" -#define ZEN_BRIGHT_COLOR_MAGENTA "\033[1;35m" -#define ZEN_BRIGHT_COLOR_CYAN "\033[1;36m" -#define ZEN_BRIGHT_COLOR_WHITE "\033[1;37m" - -#define ZEN_COLOR_RESET "\033[0m" - -namespace zen { - -RunCommand::RunCommand() -{ - m_Options.add_options()("h,help", "Print help"); - m_Options.add_option("", "n", "count", "Number of times to run command", cxxopts::value(m_RunCount), "<count>"); - m_Options.add_option("", "t", "time", "How long to run command(s) for", cxxopts::value(m_RunTime), "<seconds>"); - m_Options.add_option("", - "", - "basepath", - "Where to run command. Each run will execute in its own numbered subdirectory below this directory. Additionally, " - "stdout will be redirected to a file in the provided directory", - cxxopts::value(m_BaseDirectory), - "<path>"); - m_Options.add_option("", - "", - "max-dirs", - "Number of base directories to retain on rotation", - cxxopts::value(m_MaxBaseDirectoryCount), - "<count>"); -} - -RunCommand::~RunCommand() -{ -} - -void -RunCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) -{ - if (!ParseOptions(argc, argv)) - { - return; - } - - // Validate arguments - - if (GlobalOptions.PassthroughArgV.empty() || GlobalOptions.PassthroughArgV[0].empty()) - throw OptionParseException("No command specified. The command to run is passed in after a double dash ('--') on the command line", - m_Options.help()); - - if (m_RunCount < 0) - throw OptionParseException(fmt::format("'--count' ('{}') is invalid", m_RunCount), m_Options.help()); - - if (m_RunTime < -1 || m_RunTime == 0) - throw OptionParseException(fmt::format("'--time' ('{}') is invalid", m_RunTime), m_Options.help()); - - if (m_MaxBaseDirectoryCount < 0) - throw OptionParseException(fmt::format("'--max-dirs' ('{}') is invalid", m_MaxBaseDirectoryCount), m_Options.help()); - - if (m_RunTime > 0 && m_RunCount > 0) - throw OptionParseException(fmt::format("'--time' ('{}') conflicts with '--count' ('{}') ", m_RunTime, m_RunCount), - m_Options.help()); - - if (m_RunCount == 0) - m_RunCount = 1; - - std::filesystem::path BaseDirectory; - - if (!m_BaseDirectory.empty()) - { - BaseDirectory = m_BaseDirectory; - - if (m_MaxBaseDirectoryCount) - { - RotateDirectories(BaseDirectory, m_MaxBaseDirectoryCount); - CreateDirectories(BaseDirectory); - } - else - { - CleanDirectory(BaseDirectory, /*ForceRemoveReadOnlyFiles*/ false); - } - } - - bool TimedRun = false; - auto CommandDeadlineTime = std::chrono::system_clock::now(); - - if (m_RunTime > 0) - { - m_RunCount = 1'000'000; - TimedRun = true; - - CommandDeadlineTime += std::chrono::seconds(m_RunTime); - } - - struct RunResults - { - int ExitCode = 0; - std::chrono::duration<long, std::milli> Duration{}; - }; - - std::vector<RunResults> Results; - int ErrorCount = 0; - - std::filesystem::path ExecutablePath = SearchPathForExecutable(GlobalOptions.PassthroughArgV[0]); - std::string CommandArguments = GlobalOptions.PassthroughArgs; - - for (int i = 0; i < m_RunCount; ++i) - { - std::filesystem::path RunDir; - if (!BaseDirectory.empty()) - { - RunDir = BaseDirectory / IntNum(i + 1).c_str(); - CreateDirectories(RunDir); - } - - Stopwatch Timer; - - CreateProcOptions ProcOptions; - - if (!RunDir.empty()) - { - ProcOptions.WorkingDirectory = &RunDir; - ProcOptions.StdoutFile = RunDir / "stdout.txt"; - } - - fmt::print(ZEN_BRIGHT_COLOR_WHITE "run #{}" ZEN_COLOR_RESET ": {}\n", i + 1, GlobalOptions.PassthroughCommandLine); - - ProcessHandle Proc; - Proc.Initialize(CreateProc(ExecutablePath, GlobalOptions.PassthroughCommandLine, ProcOptions)); - if (!Proc.IsValid()) - { - throw std::runtime_error(fmt::format("failed to launch '{}'", ExecutablePath)); - } - - int ExitCode = Proc.WaitExitCode(); - - auto EndTime = std::chrono::system_clock::now(); - - if (ExitCode) - ++ErrorCount; - - Results.emplace_back(RunResults{.ExitCode = ExitCode, .Duration = std::chrono::milliseconds(Timer.GetElapsedTimeMs())}); - - if (TimedRun) - { - if (EndTime >= CommandDeadlineTime) - { - m_RunCount = i + 1; - break; - } - } - } - - fmt::print("{:>5} {:>3} {:>6}\n", "run", "rc", "time"); - int i = 0; - for (const auto& Entry : Results) - { - fmt::print("{:5} {:3} {:>6}\n", ++i, Entry.ExitCode, NiceTimeSpanMs(Entry.Duration.count())); - } - - if (ErrorCount) - { - fmt::print("run complete ({}/{} failed)\n", ErrorCount, m_RunCount); - } - else - { - fmt::print("run complete, no error exit code\n", m_RunCount); - } -} - -} // namespace zen diff --git a/src/zen/cmds/run_cmd.h b/src/zen/cmds/run_cmd.h deleted file mode 100644 index 300c08c5b..000000000 --- a/src/zen/cmds/run_cmd.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "../zen.h" - -namespace zen { - -class RunCommand : public ZenCmdBase -{ -public: - static constexpr char Name[] = "run"; - static constexpr char Description[] = "Run command with special options"; - - RunCommand(); - ~RunCommand(); - - virtual void Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override; - virtual cxxopts::Options& Options() override { return m_Options; } - virtual ZenCmdCategory& CommandCategory() const override { return g_UtilitiesCategory; } - -private: - cxxopts::Options m_Options{Name, Description}; - int m_RunCount = 0; - int m_RunTime = -1; - std::string m_BaseDirectory; - int m_MaxBaseDirectoryCount = 10; -}; - -} // namespace zen diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp index 553fac155..542788ca4 100644 --- a/src/zen/zen.cpp +++ b/src/zen/zen.cpp @@ -10,14 +10,12 @@ #include "cmds/builds_cmd.h" #include "cmds/cache_cmd.h" #include "cmds/compute_cmd.h" -#include "cmds/copy_cmd.h" #include "cmds/dedup_cmd.h" #include "cmds/exec_cmd.h" #include "cmds/hub_cmd.h" #include "cmds/info_cmd.h" #include "cmds/print_cmd.h" #include "cmds/projectstore_cmd.h" -#include "cmds/run_cmd.h" #include "cmds/serve_cmd.h" #include "cmds/service_cmd.h" #include "cmds/status_cmd.h" @@ -580,7 +578,6 @@ main(int argc, char** argv) CacheGenerateCommand CacheGenerateCmd; CacheInfoCommand CacheInfoCmd; CacheStatsCommand CacheStatsCmd; - CopyCommand CopyCmd; CopyStateCommand CopyStateCmd; CreateOplogCommand CreateOplogCmd; CreateProjectCommand CreateProjectCmd; @@ -614,7 +611,6 @@ main(int argc, char** argv) RpcReplayCommand RpcReplayCmd; RpcStartRecordingCommand RpcStartRecordingCmd; RpcStopRecordingCommand RpcStopRecordingCmd; - RunCommand RunCmd; ScrubCommand ScrubCmd; ServeCommand ServeCmd; StatusCommand StatusCmd; @@ -646,7 +642,6 @@ main(int argc, char** argv) {CacheGetCommand::Name, &CacheGetCmd, CacheGetCommand::Description}, {CacheGenerateCommand::Name, &CacheGenerateCmd, CacheGenerateCommand::Description}, {CacheStatsCommand::Name, &CacheStatsCmd, CacheStatsCommand::Description}, - {CopyCommand::Name, &CopyCmd, CopyCommand::Description}, {CopyStateCommand::Name, &CopyStateCmd, CopyStateCommand::Description}, {DedupCommand::Name, &DedupCmd, DedupCommand::Description}, {DownCommand::Name, &DownCmd, DownCommand::Description}, @@ -680,7 +675,6 @@ main(int argc, char** argv) {RpcReplayCommand::Name, &RpcReplayCmd, RpcReplayCommand::Description}, {RpcStartRecordingCommand::Name, &RpcStartRecordingCmd, RpcStartRecordingCommand::Description}, {RpcStopRecordingCommand::Name, &RpcStopRecordingCmd, RpcStopRecordingCommand::Description}, - {RunCommand::Name, &RunCmd, RunCommand::Description}, {ScrubCommand::Name, &ScrubCmd, ScrubCommand::Description}, {ServeCommand::Name, &ServeCmd, ServeCommand::Description}, {StatusCommand::Name, &StatusCmd, StatusCommand::Description}, |