aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zen/cmds/admin_cmd.cpp32
-rw-r--r--src/zen/cmds/bench_cmd.cpp10
-rw-r--r--src/zen/cmds/builds_cmd.cpp1666
-rw-r--r--src/zen/cmds/cache_cmd.cpp24
-rw-r--r--src/zen/cmds/copy_cmd.cpp4
-rw-r--r--src/zen/cmds/dedup_cmd.cpp6
-rw-r--r--src/zen/cmds/info_cmd.cpp4
-rw-r--r--src/zen/cmds/print_cmd.cpp28
-rw-r--r--src/zen/cmds/projectstore_cmd.cpp155
-rw-r--r--src/zen/cmds/rpcreplay_cmd.cpp2
-rw-r--r--src/zen/cmds/serve_cmd.cpp12
-rw-r--r--src/zen/cmds/status_cmd.cpp7
-rw-r--r--src/zen/cmds/top_cmd.cpp4
-rw-r--r--src/zen/cmds/trace_cmd.cpp6
-rw-r--r--src/zen/cmds/up_cmd.cpp41
-rw-r--r--src/zen/cmds/version_cmd.cpp2
-rw-r--r--src/zen/cmds/wipe_cmd.cpp15
-rw-r--r--src/zen/cmds/workspaces_cmd.cpp18
-rw-r--r--src/zen/zen.cpp59
-rw-r--r--src/zencore/include/zencore/logging.h1
-rw-r--r--src/zencore/logging.cpp23
-rw-r--r--src/zenserver/config.cpp2
-rw-r--r--src/zenserver/main.cpp4
23 files changed, 1048 insertions, 1077 deletions
diff --git a/src/zen/cmds/admin_cmd.cpp b/src/zen/cmds/admin_cmd.cpp
index fe2bbbdc7..dca6da6c4 100644
--- a/src/zen/cmds/admin_cmd.cpp
+++ b/src/zen/cmds/admin_cmd.cpp
@@ -51,17 +51,17 @@ ScrubCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (HttpClient::Response Response = Http.Post("/admin/scrub"sv, /* headers */ HttpClient::KeyValueMap{}, Params))
{
- ZEN_CONSOLE("scrub started OK: {}", Response.ToText());
+ ZEN_CONSOLE("Scrub started OK: {}", Response.ToText());
return 0;
}
else if (int StatusCode = (int)Response.StatusCode)
{
- ZEN_ERROR("scrub start failed: {}: {} ({})", StatusCode, ReasonStringForHttpResultCode(StatusCode), Response.ToText());
+ ZEN_CONSOLE_ERROR("Scrub start failed: {}: {} ({})", StatusCode, ReasonStringForHttpResultCode(StatusCode), Response.ToText());
}
else
{
- ZEN_ERROR("scrub start failed: {}", Response.ToText());
+ ZEN_CONSOLE_ERROR("Scrub start failed: {}", Response.ToText());
}
return 1;
@@ -259,11 +259,11 @@ GcCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Result.status_code)
{
- ZEN_ERROR("GC start failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("GC start failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("GC start failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("GC start failed: {}", Result.error.message);
}
return 1;
@@ -315,11 +315,11 @@ GcStatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Result.status_code)
{
- ZEN_ERROR("GC status failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("GC status failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("GC status failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("GC status failed: {}", Result.error.message);
}
return 1;
@@ -369,11 +369,11 @@ GcStopCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Result.status_code)
{
- ZEN_ERROR("GC status failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("GC status failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("GC status failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("GC status failed: {}", Result.error.message);
}
return 1;
@@ -416,7 +416,7 @@ JobCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
if (m_JobId == 0)
{
- ZEN_ERROR("Job id must be given");
+ throw OptionParseException("Job id must be given");
return 1;
}
}
@@ -514,7 +514,7 @@ LoggingCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_ERROR("Invalid value for parameter 'cache-write-log'. Use 'enable' or 'disable'");
+ ZEN_CONSOLE_ERROR("Invalid value for parameter 'cache-write-log'. Use 'enable' or 'disable'");
return 1;
}
}
@@ -531,7 +531,7 @@ LoggingCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_ERROR("Invalid value for parameter 'cache-access-log'. Use 'enable' or 'disable'");
+ ZEN_CONSOLE_ERROR("Invalid value for parameter 'cache-access-log'. Use 'enable' or 'disable'");
return 1;
}
}
@@ -551,12 +551,12 @@ LoggingCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
auto CopyLog = [](std::string_view SourceName, std::string_view SourcePath, std::string_view TargetPath) -> bool {
if (SourcePath.empty())
{
- ZEN_ERROR("Failed to retrieve {} log path", SourceName);
+ ZEN_CONSOLE_ERROR("Failed to retrieve {} log path", SourceName);
return false;
}
if (!CopyFile(SourcePath, TargetPath, {}))
{
- ZEN_ERROR("Failed to copy {} log file {} to output file '{}'", SourceName, SourcePath, TargetPath);
+ ZEN_CONSOLE_ERROR("Failed to copy {} log file {} to output file '{}'", SourceName, SourcePath, TargetPath);
return false;
}
return true;
@@ -642,11 +642,11 @@ FlushCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else if (int StatusCode = (int)Response.StatusCode)
{
- ZEN_ERROR("flush failed: {}: {} ({})", StatusCode, ReasonStringForHttpResultCode(StatusCode), Response.ToText());
+ ZEN_CONSOLE_ERROR("Flush failed: {}: {} ({})", StatusCode, ReasonStringForHttpResultCode(StatusCode), Response.ToText());
}
else
{
- ZEN_ERROR("flush failed: {}", Response.ToText());
+ ZEN_CONSOLE_ERROR("Flush failed: {}", Response.ToText());
}
return 1;
diff --git a/src/zen/cmds/bench_cmd.cpp b/src/zen/cmds/bench_cmd.cpp
index 86b82d838..d904a51f6 100644
--- a/src/zen/cmds/bench_cmd.cpp
+++ b/src/zen/cmds/bench_cmd.cpp
@@ -50,11 +50,11 @@ BenchCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
catch (const zen::bench::util::elevation_required_exception&)
{
- ZEN_CONSOLE("purging standby lists requires elevation. Will try launch as elevated process");
+ ZEN_CONSOLE_WARN("Purging standby lists requires elevation. Will try launch as elevated process");
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE("ERROR: {}", Ex.what());
+ ZEN_CONSOLE_ERROR("{}", Ex.what());
}
if (!Ok && !m_SingleProcess)
@@ -79,20 +79,20 @@ BenchCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_CONSOLE("ERROR: Elevated child process failed with return code {}", ExitCode);
+ ZEN_CONSOLE_ERROR("Elevated child process failed with return code {}", ExitCode);
}
}
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE("ERROR: {}", Ex.what());
+ ZEN_CONSOLE_ERROR("{}", Ex.what());
}
}
if (Ok)
{
// TODO: could also add reporting on just how much memory was purged
- ZEN_CONSOLE("purged standby lists! (took {})", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
+ ZEN_CONSOLE("Purged standby lists! (took {})", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
}
}
#endif
diff --git a/src/zen/cmds/builds_cmd.cpp b/src/zen/cmds/builds_cmd.cpp
index 8692e5941..2c6b8e50e 100644
--- a/src/zen/cmds/builds_cmd.cpp
+++ b/src/zen/cmds/builds_cmd.cpp
@@ -258,7 +258,7 @@ namespace {
}
catch (const std::exception& Ex)
{
- ZEN_ERROR("ZenState::~ZenState threw exception: {}", Ex.what());
+ ZEN_CONSOLE_ERROR("ZenState::~ZenState threw exception: {}", Ex.what());
}
}
@@ -469,7 +469,7 @@ namespace {
ZEN_ASSERT_SLOW(IsFile(SourcePath));
if (Retries > 5)
{
- ZEN_CONSOLE("Unable to overwrite file {} ({}: {}), retrying...", TargetPath, Ec.value(), Ec.message());
+ ZEN_CONSOLE_WARN("Unable to overwrite file {} ({}: {}), retrying...", TargetPath, Ec.value(), Ec.message());
}
Sleep(50 + int(Retries * 150));
Ec.clear();
@@ -701,7 +701,7 @@ namespace {
}
catch (const std::exception& Ex)
{
- ZEN_WARN("Failed removing file {}. Reason: {}", FilePath, Ex.what());
+ ZEN_CONSOLE_WARN("Failed removing file {}. Reason: {}", FilePath, Ex.what());
CleanWipe = false;
}
}
@@ -784,7 +784,7 @@ namespace {
}
catch (const std::exception& Ex)
{
- ZEN_WARN("Failed removing directory {}. Reason: {}", DirectoryToDelete, Ex.what());
+ ZEN_CONSOLE_WARN("Failed removing directory {}. Reason: {}", DirectoryToDelete, Ex.what());
CleanWipe = false;
}
@@ -1569,7 +1569,7 @@ namespace {
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE("Unable to read local state: ", Ex.what());
+ ZEN_CONSOLE_WARN("Unable to read local state: ", Ex.what());
return false;
}
}
@@ -1707,7 +1707,7 @@ namespace {
}
else
{
- ZEN_WARN("Invalid download state file at {}. '{}'", EntryPath, JsonError);
+ ZEN_CONSOLE_WARN("Invalid download state file at {}. '{}'", EntryPath, JsonError);
DeleteEntry = true;
}
}
@@ -2927,8 +2927,8 @@ namespace {
}
else
{
- ZEN_CONSOLE(
- "Warning: Build blob {} was reported as needed for upload but it was reported as existing at the start of the "
+ ZEN_CONSOLE_WARN(
+ "Build blob {} was reported as needed for upload but it was reported as existing at the start of the "
"operation. Treating it as a transient inconsistent issue and will attempt to retry finalization",
RawHash);
}
@@ -3570,8 +3570,8 @@ namespace {
}
else if (AllowMultiparts)
{
- ZEN_WARN("PreferredMultipartChunkSize is unknown. Defaulting to '{}'",
- NiceBytes(Result.PreferredMultipartChunkSize));
+ ZEN_CONSOLE_WARN("PreferredMultipartChunkSize is unknown. Defaulting to '{}'",
+ NiceBytes(Result.PreferredMultipartChunkSize));
}
}
@@ -4765,7 +4765,7 @@ namespace {
for (const std::string& Error : Errors)
{
- ZEN_CONSOLE("{}", Error);
+ ZEN_CONSOLE_ERROR("{}", Error);
}
if (!Errors.empty())
{
@@ -5671,7 +5671,7 @@ namespace {
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE("Failed reading state file {}, falling back to scannning. Reason: {}", StateFilePath, Ex.what());
+ ZEN_CONSOLE_WARN("Failed reading state file {}, falling back to scannning. Reason: {}", StateFilePath, Ex.what());
}
return HasLocalState;
}
@@ -8194,7 +8194,7 @@ namespace {
// Clean target folder
if (!CleanDirectory(Path, DefaultExcludeFolders))
{
- ZEN_WARN("Some files in {} could not be removed", Path);
+ ZEN_CONSOLE_WARN("Some files in {} could not be removed", Path);
}
RebuildFolderStateStats.CleanFolderElapsedWallTimeUs = Timer.GetElapsedTimeUs();
}
@@ -8750,7 +8750,7 @@ namespace {
ChunkBlockDescription Description = ParseChunkBlockDescription(CacheBlockMetadata);
if (Description.BlockHash == IoHash::Zero)
{
- ZEN_WARN("Unexpected/invalid block metadata received from remote cache, skipping block");
+ ZEN_CONSOLE_WARN("Unexpected/invalid block metadata received from remote cache, skipping block");
}
else
{
@@ -8787,7 +8787,7 @@ namespace {
if (Description.BlockHash == IoHash::Zero)
{
- ZEN_WARN("Unexpected/invalid block metadata received from remote store, skipping block");
+ ZEN_CONSOLE_WARN("Unexpected/invalid block metadata received from remote store, skipping block");
}
else
{
@@ -8843,7 +8843,7 @@ namespace {
BlockRawHashes.size() - OutBlockDescriptions.size());
if (AttemptFallback)
{
- ZEN_CONSOLE("{} Attemping fallback options.", ErrorDescription);
+ ZEN_CONSOLE_WARN("{} Attemping fallback options.", ErrorDescription);
std::vector<ChunkBlockDescription> AugmentedBlockDescriptions;
AugmentedBlockDescriptions.reserve(BlockRawHashes.size());
std::vector<ChunkBlockDescription> FoundBlocks =
@@ -9465,7 +9465,7 @@ namespace {
{
if (!ChunkController && !IsQuiet)
{
- ZEN_CONSOLE("Warning: Unspecified chunking algorith, using default");
+ ZEN_CONSOLE_WARN("Unspecified chunking algorith, using default");
ChunkController = CreateChunkingControllerWithFixedChunking(ChunkingControllerWithFixedChunkingSettings{});
}
@@ -10576,7 +10576,7 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
m_EncryptionKey = "abcdefghijklmnopqrstuvxyz0123456";
if (!IsQuiet)
{
- ZEN_CONSOLE("Warning: Using default encryption key");
+ ZEN_CONSOLE_WARN("Using default encryption key");
}
}
@@ -10585,7 +10585,7 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
m_EncryptionIV = "0123456789abcdef";
if (!IsQuiet)
{
- ZEN_CONSOLE("Warning: Using default encryption initialization vector");
+ ZEN_CONSOLE_WARN("Using default encryption initialization vector");
}
}
@@ -10897,7 +10897,7 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
if (m_ZenCacheHost.empty() && !IsQuiet)
{
- ZEN_CONSOLE("Warning: Failed to find any usable cache hosts out of {} using {}", CacheCount, m_Host);
+ ZEN_CONSOLE_WARN("Failed to find any usable cache hosts out of {} using {}", CacheCount, m_Host);
}
}
}
@@ -10917,7 +10917,7 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_WARN("Unable to reach cache host {}. Reason: {}", m_ZenCacheHost, TestResult.second);
+ ZEN_CONSOLE_WARN("Unable to reach cache host {}. Reason: {}", m_ZenCacheHost, TestResult.second);
}
}
}
@@ -11163,163 +11163,73 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
BoostWorkerThreads = m_BoostWorkerThreads;
UseSparseFiles = m_UseSparseFiles;
- try
+ if (SubOption == &m_ListNamespacesOptions)
{
- if (SubOption == &m_ListNamespacesOptions)
+ if (!m_ListResultPath.empty())
{
- if (!m_ListResultPath.empty())
+ if (!IsQuiet)
{
- if (!IsQuiet)
- {
- ZEN_CONSOLE("Running {}: {} (pid {})",
- GetRunningExecutablePath(),
- ZEN_CFG_VERSION_BUILD_STRING_FULL,
- GetCurrentProcessId());
- }
+ ZEN_CONSOLE("Running {}: {} (pid {})",
+ GetRunningExecutablePath(),
+ ZEN_CFG_VERSION_BUILD_STRING_FULL,
+ GetCurrentProcessId());
}
+ }
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
-
- const std::filesystem::path ZenFolderPath = m_ZenFolderPath.empty()
- ? MakeSafeAbsolutePath(std::filesystem::current_path()) / ZenFolderName
- : MakeSafeAbsolutePath(m_ZenFolderPath);
- CreateDirectories(ZenFolderPath);
- auto _ = MakeGuard([ZenFolderPath]() {
- if (CleanDirectory(ZenFolderPath, {}))
- {
- std::error_code DummyEc;
- RemoveDir(ZenFolderPath, DummyEc);
- }
- });
-
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(ZenFolderPath),
- /*RequriesNamespace*/ false,
- /*RequireBucket*/ false);
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- CbObject Response = Storage.BuildStorage->ListNamespaces(m_ListNamespacesRecursive);
- ZEN_ASSERT(ValidateCompactBinary(Response.GetView(), CbValidateMode::Default) == CbValidateError::None);
- if (m_ListResultPath.empty())
+ const std::filesystem::path ZenFolderPath = m_ZenFolderPath.empty()
+ ? MakeSafeAbsolutePath(std::filesystem::current_path()) / ZenFolderName
+ : MakeSafeAbsolutePath(m_ZenFolderPath);
+ CreateDirectories(ZenFolderPath);
+ auto _ = MakeGuard([ZenFolderPath]() {
+ if (CleanDirectory(ZenFolderPath, {}))
{
- ExtendableStringBuilder<1024> SB;
- CompactBinaryToJson(Response.GetView(), SB);
- ZEN_CONSOLE("{}", SB.ToView());
- }
- else
- {
- std::filesystem::path ListResultPath = MakeSafeAbsolutePath(m_ListResultPath);
- if (ToLower(ListResultPath.extension().string()) == ".cbo")
- {
- MemoryView ResponseView = Response.GetView();
- WriteFile(ListResultPath, IoBuffer(IoBuffer::Wrap, ResponseView.GetData(), ResponseView.GetSize()));
- }
- else
- {
- ExtendableStringBuilder<1024> SB;
- CompactBinaryToJson(Response.GetView(), SB);
- WriteFile(ListResultPath, IoBuffer(IoBuffer::Wrap, SB.Data(), SB.Size()));
- }
+ std::error_code DummyEc;
+ RemoveDir(ZenFolderPath, DummyEc);
}
+ });
- return 0;
- }
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(ZenFolderPath),
+ /*RequriesNamespace*/ false,
+ /*RequireBucket*/ false);
- if (SubOption == &m_ListOptions)
+ CbObject Response = Storage.BuildStorage->ListNamespaces(m_ListNamespacesRecursive);
+ ZEN_ASSERT(ValidateCompactBinary(Response.GetView(), CbValidateMode::Default) == CbValidateError::None);
+ if (m_ListResultPath.empty())
{
- MakeSafeAbsolutePathÍnPlace(m_ListQueryPath);
- MakeSafeAbsolutePathÍnPlace(m_ListResultPath);
-
- if (!m_ListResultPath.empty())
- {
- if (!IsQuiet)
- {
- ZEN_CONSOLE("Running {}: {} (pid {})",
- GetRunningExecutablePath(),
- ZEN_CFG_VERSION_BUILD_STRING_FULL,
- GetCurrentProcessId());
- }
- }
- CbObject QueryObject;
- if (m_ListQueryPath.empty())
+ ExtendableStringBuilder<1024> SB;
+ CompactBinaryToJson(Response.GetView(), SB);
+ ZEN_CONSOLE("{}", SB.ToView());
+ }
+ else
+ {
+ std::filesystem::path ListResultPath = MakeSafeAbsolutePath(m_ListResultPath);
+ if (ToLower(ListResultPath.extension().string()) == ".cbo")
{
- CbObjectWriter QueryWriter;
- QueryWriter.BeginObject("query");
- QueryWriter.EndObject(); // query
- QueryObject = QueryWriter.Save();
+ MemoryView ResponseView = Response.GetView();
+ WriteFile(ListResultPath, IoBuffer(IoBuffer::Wrap, ResponseView.GetData(), ResponseView.GetSize()));
}
else
{
- if (ToLower(m_ListQueryPath.extension().string()) == ".cbo")
- {
- QueryObject = LoadCompactBinaryObject(IoBufferBuilder::MakeFromFile(m_ListQueryPath));
- }
- else
- {
- IoBuffer MetaDataJson = ReadFile(m_ListQueryPath).Flatten();
- std::string_view Json(reinterpret_cast<const char*>(MetaDataJson.GetData()), MetaDataJson.GetSize());
- std::string JsonError;
- QueryObject = LoadCompactBinaryFromJson(Json, JsonError).AsObject();
- if (!JsonError.empty())
- {
- throw std::runtime_error(
- fmt::format("build metadata file '{}' is malformed. Reason: '{}'", m_ListQueryPath, JsonError));
- }
- }
- }
-
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
-
- if (m_ZenFolderPath.empty())
- {
- m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
- }
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
-
- CreateDirectories(m_ZenFolderPath);
- auto _ = MakeGuard([this]() {
- if (CleanDirectory(m_ZenFolderPath, {}))
- {
- std::error_code DummyEc;
- RemoveDir(m_ZenFolderPath, DummyEc);
- }
- });
-
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ false);
-
- CbObject Response = Storage.BuildStorage->ListBuilds(QueryObject);
- ZEN_ASSERT(ValidateCompactBinary(Response.GetView(), CbValidateMode::Default) == CbValidateError::None);
- if (m_ListResultPath.empty())
- {
ExtendableStringBuilder<1024> SB;
CompactBinaryToJson(Response.GetView(), SB);
- ZEN_CONSOLE("{}", SB.ToView());
+ WriteFile(ListResultPath, IoBuffer(IoBuffer::Wrap, SB.Data(), SB.Size()));
}
- else
- {
- if (ToLower(m_ListResultPath.extension().string()) == ".cbo")
- {
- MemoryView ResponseView = Response.GetView();
- WriteFile(m_ListResultPath, IoBuffer(IoBuffer::Wrap, ResponseView.GetData(), ResponseView.GetSize()));
- }
- else
- {
- ExtendableStringBuilder<1024> SB;
- CompactBinaryToJson(Response.GetView(), SB);
- WriteFile(m_ListResultPath, IoBuffer(IoBuffer::Wrap, SB.Data(), SB.Size()));
- }
- }
-
- return 0;
}
- if (SubOption == &m_UploadOptions)
+ return 0;
+ }
+
+ if (SubOption == &m_ListOptions)
+ {
+ MakeSafeAbsolutePathÍnPlace(m_ListQueryPath);
+ MakeSafeAbsolutePathÍnPlace(m_ListResultPath);
+
+ if (!m_ListResultPath.empty())
{
if (!IsQuiet)
{
@@ -11328,544 +11238,439 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
ZEN_CFG_VERSION_BUILD_STRING_FULL,
GetCurrentProcessId());
}
-
- ZenState InstanceState;
-
- ParsePath();
-
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
-
- if (m_ZenFolderPath.empty())
+ }
+ CbObject QueryObject;
+ if (m_ListQueryPath.empty())
+ {
+ CbObjectWriter QueryWriter;
+ QueryWriter.BeginObject("query");
+ QueryWriter.EndObject(); // query
+ QueryObject = QueryWriter.Save();
+ }
+ else
+ {
+ if (ToLower(m_ListQueryPath.extension().string()) == ".cbo")
{
- m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
+ QueryObject = LoadCompactBinaryObject(IoBufferBuilder::MakeFromFile(m_ListQueryPath));
}
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
-
- CreateDirectories(m_ZenFolderPath);
- auto _ = MakeGuard([this]() {
- if (CleanDirectory(m_ZenFolderPath, {}))
+ else
+ {
+ IoBuffer MetaDataJson = ReadFile(m_ListQueryPath).Flatten();
+ std::string_view Json(reinterpret_cast<const char*>(MetaDataJson.GetData()), MetaDataJson.GetSize());
+ std::string JsonError;
+ QueryObject = LoadCompactBinaryFromJson(Json, JsonError).AsObject();
+ if (!JsonError.empty())
{
- std::error_code DummyEc;
- RemoveDir(m_ZenFolderPath, DummyEc);
+ throw std::runtime_error(
+ fmt::format("build metadata file '{}' is malformed. Reason: '{}'", m_ListQueryPath, JsonError));
}
- });
+ }
+ }
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- if (m_BuildPartName.empty())
- {
- m_BuildPartName = m_Path.filename().string();
- }
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
- const Oid BuildId = m_BuildId.empty() ? Oid::NewOid() : ParseBuildId();
- if (m_BuildId.empty())
- {
- m_BuildId = BuildId.ToString();
- }
- const Oid BuildPartId = m_BuildPartId.empty() ? Oid::NewOid() : ParseBuildPartId();
- if (m_BuildPartId.empty())
+ CreateDirectories(m_ZenFolderPath);
+ auto _ = MakeGuard([this]() {
+ if (CleanDirectory(m_ZenFolderPath, {}))
{
- m_BuildPartId = BuildPartId.ToString();
+ std::error_code DummyEc;
+ RemoveDir(m_ZenFolderPath, DummyEc);
}
+ });
- CbObject MetaData = ParseBuildMetadata();
-
- const std::filesystem::path TempDir = ZenTempFolderPath(m_ZenFolderPath);
-
- m_ManifestPath = RemoveQuotes(m_ManifestPath);
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ false);
- UploadFolder(Storage,
- BuildId,
- BuildPartId,
- m_BuildPartName,
- m_Path,
- TempDir,
- m_ManifestPath,
- m_FindBlockMaxCount,
- m_BlockReuseMinPercentLimit,
- m_AllowMultiparts,
- MetaData,
- m_CreateBuild,
- m_Clean,
- m_PostUploadVerify);
-
- if (false)
- {
- if (!IsQuiet)
- {
- ZEN_CONSOLE(
- "{}:\n"
- "Read: {}\n"
- "Write: {}\n"
- "Requests: {}\n"
- "Avg Request Time: {}\n"
- "Avg I/O Time: {}",
- Storage.StorageName,
- NiceBytes(StorageStats.TotalBytesRead.load()),
- NiceBytes(StorageStats.TotalBytesWritten.load()),
- StorageStats.TotalRequestCount.load(),
- StorageStats.TotalExecutionTimeUs.load() > 0
- ? NiceTimeSpanMs(StorageStats.TotalExecutionTimeUs.load() / 1000 / StorageStats.TotalRequestCount.load())
- : 0,
- StorageStats.TotalRequestCount.load() > 0
- ? NiceTimeSpanMs(StorageStats.TotalRequestTimeUs.load() / 1000 / StorageStats.TotalRequestCount.load())
- : 0);
- }
- }
- return AbortFlag ? 11 : 0;
+ CbObject Response = Storage.BuildStorage->ListBuilds(QueryObject);
+ ZEN_ASSERT(ValidateCompactBinary(Response.GetView(), CbValidateMode::Default) == CbValidateError::None);
+ if (m_ListResultPath.empty())
+ {
+ ExtendableStringBuilder<1024> SB;
+ CompactBinaryToJson(Response.GetView(), SB);
+ ZEN_CONSOLE("{}", SB.ToView());
}
-
- if (SubOption == &m_DownloadOptions)
+ else
{
- if (!IsQuiet)
+ if (ToLower(m_ListResultPath.extension().string()) == ".cbo")
{
- ZEN_CONSOLE("Running {}: {} (pid {})",
- GetRunningExecutablePath(),
- ZEN_CFG_VERSION_BUILD_STRING_FULL,
- GetCurrentProcessId());
+ MemoryView ResponseView = Response.GetView();
+ WriteFile(m_ListResultPath, IoBuffer(IoBuffer::Wrap, ResponseView.GetData(), ResponseView.GetSize()));
}
-
- ZenState InstanceState;
-
- ParsePath();
- ParseFileFilters();
-
- if (m_ZenFolderPath.empty())
+ else
{
- m_ZenFolderPath = m_Path / ZenFolderName;
+ ExtendableStringBuilder<1024> SB;
+ CompactBinaryToJson(Response.GetView(), SB);
+ WriteFile(m_ListResultPath, IoBuffer(IoBuffer::Wrap, SB.Data(), SB.Size()));
}
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+ }
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
+ return 0;
+ }
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ if (SubOption == &m_UploadOptions)
+ {
+ if (!IsQuiet)
+ {
+ ZEN_CONSOLE("Running {}: {} (pid {})", GetRunningExecutablePath(), ZEN_CFG_VERSION_BUILD_STRING_FULL, GetCurrentProcessId());
+ }
- const Oid BuildId = ParseBuildId();
+ ZenState InstanceState;
- if (m_PostDownloadVerify && m_PrimeCacheOnly)
- {
- throw zen::OptionParseException(
- fmt::format("'cache-prime-only' option is not compatible with 'verify' option\n{}", SubOption->help()));
- }
+ ParsePath();
- if (m_Clean && m_PrimeCacheOnly)
- {
- ZEN_WARN("ignoring 'clean' option when 'cache-prime-only' is enabled");
- }
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
+
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
- if (m_AllowPartialBlockRequests && m_PrimeCacheOnly)
+ CreateDirectories(m_ZenFolderPath);
+ auto _ = MakeGuard([this]() {
+ if (CleanDirectory(m_ZenFolderPath, {}))
{
- ZEN_WARN("ignoring 'allow-partial-block-requests' option when 'cache-prime-only' is enabled");
+ std::error_code DummyEc;
+ RemoveDir(m_ZenFolderPath, DummyEc);
}
+ });
- std::vector<Oid> BuildPartIds = ParseBuildPartIds();
- std::vector<std::string> BuildPartNames = ParseBuildPartNames();
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
- // TODO: Add file filters
- DownloadFolder(Storage,
- BuildId,
- BuildPartIds,
- BuildPartNames,
- m_Path,
- m_ZenFolderPath,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests && !m_PrimeCacheOnly,
- m_Clean,
- m_PostDownloadVerify,
- m_PrimeCacheOnly,
- m_EnableScavenging,
- m_IncludeWildcard,
- m_ExcludeWildcard);
+ if (m_BuildPartName.empty())
+ {
+ m_BuildPartName = m_Path.filename().string();
+ }
- return AbortFlag ? 11 : 0;
+ const Oid BuildId = m_BuildId.empty() ? Oid::NewOid() : ParseBuildId();
+ if (m_BuildId.empty())
+ {
+ m_BuildId = BuildId.ToString();
}
+ const Oid BuildPartId = m_BuildPartId.empty() ? Oid::NewOid() : ParseBuildPartId();
+ if (m_BuildPartId.empty())
+ {
+ m_BuildPartId = BuildPartId.ToString();
+ }
+
+ CbObject MetaData = ParseBuildMetadata();
+
+ const std::filesystem::path TempDir = ZenTempFolderPath(m_ZenFolderPath);
- if (SubOption == &m_LsOptions)
+ m_ManifestPath = RemoveQuotes(m_ManifestPath);
+
+ UploadFolder(Storage,
+ BuildId,
+ BuildPartId,
+ m_BuildPartName,
+ m_Path,
+ TempDir,
+ m_ManifestPath,
+ m_FindBlockMaxCount,
+ m_BlockReuseMinPercentLimit,
+ m_AllowMultiparts,
+ MetaData,
+ m_CreateBuild,
+ m_Clean,
+ m_PostUploadVerify);
+
+ if (false)
{
if (!IsQuiet)
{
- ZEN_CONSOLE("Running {}: {} (pid {})",
- GetRunningExecutablePath(),
- ZEN_CFG_VERSION_BUILD_STRING_FULL,
- GetCurrentProcessId());
- }
-
- ZenState InstanceState;
+ ZEN_CONSOLE(
+ "{}:\n"
+ "Read: {}\n"
+ "Write: {}\n"
+ "Requests: {}\n"
+ "Avg Request Time: {}\n"
+ "Avg I/O Time: {}",
+ Storage.StorageName,
+ NiceBytes(StorageStats.TotalBytesRead.load()),
+ NiceBytes(StorageStats.TotalBytesWritten.load()),
+ StorageStats.TotalRequestCount.load(),
+ StorageStats.TotalExecutionTimeUs.load() > 0
+ ? NiceTimeSpanMs(StorageStats.TotalExecutionTimeUs.load() / 1000 / StorageStats.TotalRequestCount.load())
+ : 0,
+ StorageStats.TotalRequestCount.load() > 0
+ ? NiceTimeSpanMs(StorageStats.TotalRequestTimeUs.load() / 1000 / StorageStats.TotalRequestCount.load())
+ : 0);
+ }
+ }
+ return AbortFlag ? 11 : 0;
+ }
- ParseFileFilters();
+ if (SubOption == &m_DownloadOptions)
+ {
+ if (!IsQuiet)
+ {
+ ZEN_CONSOLE("Running {}: {} (pid {})", GetRunningExecutablePath(), ZEN_CFG_VERSION_BUILD_STRING_FULL, GetCurrentProcessId());
+ }
- if (m_ZenFolderPath.empty())
- {
- m_ZenFolderPath = m_Path / ZenFolderName;
- }
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+ ZenState InstanceState;
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
+ ParsePath();
+ ParseFileFilters();
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = m_Path / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
- const Oid BuildId = ParseBuildId();
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- std::vector<Oid> BuildPartIds = ParseBuildPartIds();
- std::vector<std::string> BuildPartNames = ParseBuildPartNames();
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
- ListBuild(Storage, BuildId, BuildPartIds, BuildPartNames, m_IncludeWildcard, m_ExcludeWildcard);
+ const Oid BuildId = ParseBuildId();
- return AbortFlag ? 11 : 0;
+ if (m_PostDownloadVerify && m_PrimeCacheOnly)
+ {
+ throw zen::OptionParseException(
+ fmt::format("'cache-prime-only' option is not compatible with 'verify' option\n{}", SubOption->help()));
}
- if (SubOption == &m_DiffOptions)
+ if (m_Clean && m_PrimeCacheOnly)
{
- ParsePath();
- ParseDiffPath();
-
- DiffFolders(m_Path, m_DiffPath, m_OnlyChunked);
- return AbortFlag ? 11 : 0;
+ ZEN_CONSOLE_WARN("Ignoring 'clean' option when 'cache-prime-only' is enabled");
}
- if (SubOption == &m_FetchBlobOptions)
+ if (m_AllowPartialBlockRequests && m_PrimeCacheOnly)
{
- if (!IsQuiet)
- {
- ZEN_CONSOLE("Running {}: {} (pid {})",
- GetRunningExecutablePath(),
- ZEN_CFG_VERSION_BUILD_STRING_FULL,
- GetCurrentProcessId());
- }
+ ZEN_CONSOLE_WARN("Ignoring 'allow-partial-block-requests' option when 'cache-prime-only' is enabled");
+ }
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
+ std::vector<Oid> BuildPartIds = ParseBuildPartIds();
+ std::vector<std::string> BuildPartNames = ParseBuildPartNames();
- if (m_ZenFolderPath.empty())
- {
- m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
- }
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+ // TODO: Add file filters
+ DownloadFolder(Storage,
+ BuildId,
+ BuildPartIds,
+ BuildPartNames,
+ m_Path,
+ m_ZenFolderPath,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests && !m_PrimeCacheOnly,
+ m_Clean,
+ m_PostDownloadVerify,
+ m_PrimeCacheOnly,
+ m_EnableScavenging,
+ m_IncludeWildcard,
+ m_ExcludeWildcard);
- CreateDirectories(m_ZenFolderPath);
- auto _ = MakeGuard([this]() {
- if (CleanDirectory(m_ZenFolderPath, {}))
- {
- std::error_code DummyEc;
- RemoveDir(m_ZenFolderPath, DummyEc);
- }
- });
-
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ return AbortFlag ? 11 : 0;
+ }
- IoHash BlobHash = ParseBlobHash();
+ if (SubOption == &m_LsOptions)
+ {
+ if (!IsQuiet)
+ {
+ ZEN_CONSOLE("Running {}: {} (pid {})", GetRunningExecutablePath(), ZEN_CFG_VERSION_BUILD_STRING_FULL, GetCurrentProcessId());
+ }
- const Oid BuildId = Oid::FromHexString(m_BuildId);
+ ZenState InstanceState;
- uint64_t CompressedSize;
- uint64_t DecompressedSize;
- ValidateBlob(*Storage.BuildStorage, BuildId, BlobHash, CompressedSize, DecompressedSize);
- if (AbortFlag)
- {
- return 11;
- }
- if (!IsQuiet)
- {
- ZEN_CONSOLE("Blob '{}' has a compressed size {} and a decompressed size of {} bytes",
- BlobHash,
- CompressedSize,
- DecompressedSize);
- }
- return 0;
- }
+ ParseFileFilters();
- if (SubOption == &m_ValidateBuildPartOptions)
+ if (m_ZenFolderPath.empty())
{
- if (!IsQuiet)
- {
- ZEN_CONSOLE("Running {}: {} (pid {})",
- GetRunningExecutablePath(),
- ZEN_CFG_VERSION_BUILD_STRING_FULL,
- GetCurrentProcessId());
- }
+ m_ZenFolderPath = m_Path / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
- ZenState InstanceState;
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
- if (m_ZenFolderPath.empty())
- {
- m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
- }
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
-
- CreateDirectories(m_ZenFolderPath);
- auto _ = MakeGuard([this]() {
- if (CleanDirectory(m_ZenFolderPath, {}))
- {
- std::error_code DummyEc;
- RemoveDir(m_ZenFolderPath, DummyEc);
- }
- });
+ const Oid BuildId = ParseBuildId();
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ std::vector<Oid> BuildPartIds = ParseBuildPartIds();
+ std::vector<std::string> BuildPartNames = ParseBuildPartNames();
- Oid BuildId = ParseBuildId();
+ ListBuild(Storage, BuildId, BuildPartIds, BuildPartNames, m_IncludeWildcard, m_ExcludeWildcard);
- if (!m_BuildPartName.empty() && !m_BuildPartId.empty())
- {
- throw zen::OptionParseException(fmt::format("build-part-id conflicts with build-part-name\n{}", SubOption->help()));
- }
+ return AbortFlag ? 11 : 0;
+ }
- const Oid BuildPartId = m_BuildPartName.empty() ? Oid::Zero : ParseBuildPartId();
+ if (SubOption == &m_DiffOptions)
+ {
+ ParsePath();
+ ParseDiffPath();
- ValidateStatistics ValidateStats;
- DownloadStatistics DownloadStats;
- ValidateBuildPart(*Storage.BuildStorage, BuildId, BuildPartId, m_BuildPartName, ValidateStats, DownloadStats);
+ DiffFolders(m_Path, m_DiffPath, m_OnlyChunked);
+ return AbortFlag ? 11 : 0;
+ }
- return AbortFlag ? 13 : 0;
+ if (SubOption == &m_FetchBlobOptions)
+ {
+ if (!IsQuiet)
+ {
+ ZEN_CONSOLE("Running {}: {} (pid {})", GetRunningExecutablePath(), ZEN_CFG_VERSION_BUILD_STRING_FULL, GetCurrentProcessId());
}
- if (SubOption == &m_MultiTestDownloadOptions)
- {
- m_SystemRootDir = (GetRunningExecutablePath().parent_path() / ".tmpzensystem").make_preferred();
- CreateDirectories(m_SystemRootDir);
- CleanDirectory(m_SystemRootDir, {});
- auto _ = MakeGuard([&]() { DeleteDirectories(m_SystemRootDir); });
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- ParsePath();
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
- if (m_ZenFolderPath.empty())
+ CreateDirectories(m_ZenFolderPath);
+ auto _ = MakeGuard([this]() {
+ if (CleanDirectory(m_ZenFolderPath, {}))
{
- m_ZenFolderPath = m_Path / ZenFolderName;
+ std::error_code DummyEc;
+ RemoveDir(m_ZenFolderPath, DummyEc);
}
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+ });
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ IoHash BlobHash = ParseBlobHash();
- Stopwatch Timer;
- for (const std::string& BuildIdString : m_BuildIds)
- {
- Oid BuildId = Oid::FromHexString(RemoveQuotes(BuildIdString));
- if (BuildId == Oid::Zero)
- {
- throw zen::OptionParseException(fmt::format("invalid build id {}\n{}", BuildIdString, SubOption->help()));
- }
- DownloadFolder(Storage,
- BuildId,
- {},
- {},
- m_Path,
- m_ZenFolderPath,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- BuildIdString == m_BuildIds.front(),
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
- {
- ZEN_CONSOLE("Download cancelled");
- return 11;
- }
- if (!IsQuiet)
- {
- ZEN_CONSOLE("\n");
- }
- }
- if (!IsQuiet)
- {
- ZEN_CONSOLE("Completed in {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
- }
- return 0;
- }
+ const Oid BuildId = Oid::FromHexString(m_BuildId);
- auto ParseZenProcessId = [&]() {
- if (m_ZenProcessId == -1)
- {
- const std::filesystem::path RunningExecutablePath = GetRunningExecutablePath();
- ProcessHandle RunningProcess;
- std::error_code Ec = FindProcess(RunningExecutablePath, RunningProcess, /*IncludeSelf*/ false);
- if (Ec)
- {
- throw std::runtime_error(
- fmt::format("Failed finding process running '{}', reason: '{}'", RunningExecutablePath, Ec.message()));
- }
- if (!RunningProcess.IsValid())
- {
- throw zen::OptionParseException(
- fmt::format("Unable to find a running instance of the zen executable '{}'", RunningExecutablePath));
- }
- m_ZenProcessId = RunningProcess.Pid();
- }
- };
-
- if (SubOption == &m_PauseOptions)
+ uint64_t CompressedSize;
+ uint64_t DecompressedSize;
+ ValidateBlob(*Storage.BuildStorage, BuildId, BlobHash, CompressedSize, DecompressedSize);
+ if (AbortFlag)
{
- ParseZenProcessId();
- ZenState RunningState(m_ZenProcessId);
- RunningState.StateData().Pause.store(true);
- return 0;
+ return 11;
}
-
- if (SubOption == &m_ResumeOptions)
+ if (!IsQuiet)
{
- ParseZenProcessId();
- ZenState RunningState(m_ZenProcessId);
- RunningState.StateData().Pause.store(false);
- return 0;
+ ZEN_CONSOLE("Blob '{}' has a compressed size {} and a decompressed size of {} bytes",
+ BlobHash,
+ CompressedSize,
+ DecompressedSize);
}
+ return 0;
+ }
- if (SubOption == &m_AbortOptions)
+ if (SubOption == &m_ValidateBuildPartOptions)
+ {
+ if (!IsQuiet)
{
- ParseZenProcessId();
- ZenState RunningState(m_ZenProcessId);
- RunningState.StateData().Abort.store(true);
- return 0;
+ ZEN_CONSOLE("Running {}: {} (pid {})", GetRunningExecutablePath(), ZEN_CFG_VERSION_BUILD_STRING_FULL, GetCurrentProcessId());
}
- if (SubOption == &m_TestOptions)
- {
- m_SystemRootDir = (GetRunningExecutablePath().parent_path() / ".tmpzensystem").make_preferred();
- CreateDirectories(m_SystemRootDir);
- CleanDirectory(m_SystemRootDir, {});
- auto _ = MakeGuard([&]() { DeleteDirectories(m_SystemRootDir); });
+ ZenState InstanceState;
- ParsePath();
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- if (m_OverrideHost.empty() && m_StoragePath.empty())
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = std::filesystem::current_path() / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+
+ CreateDirectories(m_ZenFolderPath);
+ auto _ = MakeGuard([this]() {
+ if (CleanDirectory(m_ZenFolderPath, {}))
{
- m_StoragePath = (GetRunningExecutablePath().parent_path() / ".tmpstore").make_preferred();
- CreateDirectories(m_StoragePath);
- CleanDirectory(m_StoragePath, {});
- m_StoragePath = m_StoragePath.generic_string();
+ std::error_code DummyEc;
+ RemoveDir(m_ZenFolderPath, DummyEc);
}
+ });
- auto __ = MakeGuard([&]() {
- if (m_OverrideHost.empty() && m_StoragePath.empty())
- {
- DeleteDirectories(m_StoragePath);
- }
- });
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
- BuildStorage::Statistics StorageStats;
- BuildStorageCache::Statistics StorageCacheStats;
+ Oid BuildId = ParseBuildId();
- const std::filesystem::path DownloadPath = m_Path.parent_path() / (m_BuildPartName + "_test");
- const std::filesystem::path DownloadPath2 = m_Path.parent_path() / (m_BuildPartName + "_test2");
+ if (!m_BuildPartName.empty() && !m_BuildPartId.empty())
+ {
+ throw zen::OptionParseException(fmt::format("build-part-id conflicts with build-part-name\n{}", SubOption->help()));
+ }
- auto ___ = MakeGuard([DownloadPath, DownloadPath2]() {
- CleanDirectory(DownloadPath, true);
- DeleteDirectories(DownloadPath);
- CleanDirectory(DownloadPath2, true);
- DeleteDirectories(DownloadPath2);
- });
+ const Oid BuildPartId = m_BuildPartName.empty() ? Oid::Zero : ParseBuildPartId();
- if (m_ZenFolderPath.empty())
- {
- m_ZenFolderPath = m_Path / ZenFolderName;
- }
- MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+ ValidateStatistics ValidateStats;
+ DownloadStatistics DownloadStats;
+ ValidateBuildPart(*Storage.BuildStorage, BuildId, BuildPartId, m_BuildPartName, ValidateStats, DownloadStats);
- StorageInstance Storage = CreateBuildStorage(StorageStats,
- StorageCacheStats,
- ZenTempFolderPath(m_ZenFolderPath),
- /*RequriesNamespace*/ true,
- /*RequireBucket*/ true);
+ return AbortFlag ? 13 : 0;
+ }
- m_BuildId = Oid::NewOid().ToString();
- m_BuildPartName = m_Path.filename().string();
- m_BuildPartId = Oid::NewOid().ToString();
- m_CreateBuild = true;
+ if (SubOption == &m_MultiTestDownloadOptions)
+ {
+ m_SystemRootDir = (GetRunningExecutablePath().parent_path() / ".tmpzensystem").make_preferred();
+ CreateDirectories(m_SystemRootDir);
+ CleanDirectory(m_SystemRootDir, {});
+ auto _ = MakeGuard([&]() { DeleteDirectories(m_SystemRootDir); });
- const Oid BuildId = Oid::FromHexString(m_BuildId);
- const Oid BuildPartId = Oid::FromHexString(m_BuildPartId);
+ ParsePath();
- auto MakeMetaData = [](const Oid& BuildId) -> CbObject {
- CbObjectWriter BuildMetaDataWriter;
- {
- const uint32_t CL = BuildId.OidBits[2];
- BuildMetaDataWriter.AddString("name", fmt::format("++Test+Main-CL-{}", CL));
- BuildMetaDataWriter.AddString("branch", "ZenTestBuild");
- BuildMetaDataWriter.AddString("baselineBranch", "ZenTestBuild");
- BuildMetaDataWriter.AddString("platform", "Windows");
- BuildMetaDataWriter.AddString("project", "Test");
- BuildMetaDataWriter.AddInteger("changelist", CL);
- BuildMetaDataWriter.AddString("buildType", "test-folder");
- }
- return BuildMetaDataWriter.Save();
- };
- CbObject MetaData = MakeMetaData(Oid::TryFromHexString(m_BuildId));
- {
- ExtendableStringBuilder<256> SB;
- CompactBinaryToJson(MetaData, SB);
- ZEN_CONSOLE("Upload Build {}, Part {} ({}) from '{}'\n{}", m_BuildId, BuildPartId, m_BuildPartName, m_Path, SB.ToView());
- }
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = m_Path / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
- const std::filesystem::path UploadTempDir = UploadTempDirectory(m_Path);
- // std::filesystem::path UploadTempDir = m_ZenFolderPath / "upload_tmp";
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- UploadFolder(Storage,
- BuildId,
- BuildPartId,
- m_BuildPartName,
- m_Path,
- UploadTempDir,
- {},
- m_FindBlockMaxCount,
- m_BlockReuseMinPercentLimit,
- m_AllowMultiparts,
- MetaData,
- true,
- false,
- true);
- if (AbortFlag)
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
+
+ Stopwatch Timer;
+ for (const std::string& BuildIdString : m_BuildIds)
+ {
+ Oid BuildId = Oid::FromHexString(RemoveQuotes(BuildIdString));
+ if (BuildId == Oid::Zero)
{
- ZEN_CONSOLE("Upload failed.");
- return 11;
+ throw zen::OptionParseException(fmt::format("invalid build id {}\n{}", BuildIdString, SubOption->help()));
}
-
- ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}'", BuildId, BuildPartId, m_BuildPartName, DownloadPath);
DownloadFolder(Storage,
BuildId,
- {BuildPartId},
{},
- DownloadPath,
- DownloadPath / ZenFolderName,
+ {},
+ m_Path,
+ m_ZenFolderPath,
m_SystemRootDir,
m_AllowMultiparts,
m_AllowPartialBlockRequests,
- true,
+ BuildIdString == m_BuildIds.front(),
true,
false,
m_EnableScavenging,
@@ -11873,306 +11678,445 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
""sv);
if (AbortFlag)
{
- ZEN_CONSOLE("Download failed.");
+ ZEN_CONSOLE("Download cancelled");
return 11;
}
+ if (!IsQuiet)
+ {
+ ZEN_CONSOLE("\n");
+ }
+ }
+ if (!IsQuiet)
+ {
+ ZEN_CONSOLE("Completed in {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
+ }
+ return 0;
+ }
- ZEN_CONSOLE("\nRe-download Build {}, Part {} ({}) to '{}' (identical target)",
- BuildId,
- BuildPartId,
- m_BuildPartName,
- DownloadPath);
- DownloadFolder(Storage,
- BuildId,
- {BuildPartId},
- {},
- DownloadPath,
- DownloadPath / ZenFolderName,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- false,
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
+ auto ParseZenProcessId = [&]() {
+ if (m_ZenProcessId == -1)
+ {
+ const std::filesystem::path RunningExecutablePath = GetRunningExecutablePath();
+ ProcessHandle RunningProcess;
+ std::error_code Ec = FindProcess(RunningExecutablePath, RunningProcess, /*IncludeSelf*/ false);
+ if (Ec)
{
- ZEN_CONSOLE("Re-download failed. (identical target)");
- return 11;
+ throw std::runtime_error(
+ fmt::format("Failed finding process running '{}', reason: '{}'", RunningExecutablePath, Ec.message()));
+ }
+ if (!RunningProcess.IsValid())
+ {
+ throw zen::OptionParseException(
+ fmt::format("Unable to find a running instance of the zen executable '{}'", RunningExecutablePath));
}
+ m_ZenProcessId = RunningProcess.Pid();
+ }
+ };
- auto ScrambleDir = [](const std::filesystem::path& Path) {
- ZEN_CONSOLE("\nScrambling '{}'", Path);
- Stopwatch Timer;
- DirectoryContent DownloadContent;
- GetDirectoryContent(
- Path,
- DirectoryContentFlags::Recursive | DirectoryContentFlags::IncludeFiles | DirectoryContentFlags::IncludeFileSizes,
- DownloadContent);
- auto IsAcceptedFolder = [ExcludeFolders = DefaultExcludeFolders, Path](const std::filesystem::path& AbsolutePath) -> bool {
- std::string RelativePath = std::filesystem::relative(AbsolutePath, Path).generic_string();
- for (const std::string_view& ExcludeFolder : ExcludeFolders)
- {
- if (RelativePath.starts_with(ExcludeFolder))
- {
- if (RelativePath.length() == ExcludeFolder.length())
- {
- return false;
- }
- else if (RelativePath[ExcludeFolder.length()] == '/')
- {
- return false;
- }
- }
- }
- return true;
- };
+ if (SubOption == &m_PauseOptions)
+ {
+ ParseZenProcessId();
+ ZenState RunningState(m_ZenProcessId);
+ RunningState.StateData().Pause.store(true);
+ return 0;
+ }
- ParallelWork Work(AbortFlag, PauseFlag);
+ if (SubOption == &m_ResumeOptions)
+ {
+ ParseZenProcessId();
+ ZenState RunningState(m_ZenProcessId);
+ RunningState.StateData().Pause.store(false);
+ return 0;
+ }
- uint32_t Randomizer = 0;
- auto FileSizeIt = DownloadContent.FileSizes.begin();
- for (const std::filesystem::path& FilePath : DownloadContent.Files)
- {
- if (IsAcceptedFolder(FilePath))
- {
- uint32_t Case = (Randomizer++) % 7;
- switch (Case)
- {
- case 0:
- {
- uint64_t SourceSize = *FileSizeIt;
- if (SourceSize > 256)
- {
- Work.ScheduleWork(
- GetIOWorkerPool(),
- [SourceSize, FilePath = std::filesystem::path(FilePath)](std::atomic<bool>&) {
- if (!AbortFlag)
- {
- bool IsReadOnly = SetFileReadOnlyWithRetry(FilePath, false);
- {
- BasicFile Source(FilePath, BasicFile::Mode::kWrite);
- uint64_t RangeSize = Min(SourceSize / 3, 512u * 1024u);
- IoBuffer TempBuffer1(RangeSize);
- IoBuffer TempBuffer2(RangeSize);
- IoBuffer TempBuffer3(RangeSize);
- Source.Read(TempBuffer1.GetMutableView().GetData(), RangeSize, 0);
- Source.Read(TempBuffer2.GetMutableView().GetData(), RangeSize, SourceSize / 2);
- Source.Read(TempBuffer3.GetMutableView().GetData(),
- RangeSize,
- SourceSize - RangeSize);
- Source.Write(TempBuffer1, SourceSize / 2);
- Source.Write(TempBuffer2, SourceSize - RangeSize);
- Source.Write(TempBuffer3, SourceSize - 0);
- }
- if (IsReadOnly)
- {
- SetFileReadOnly(FilePath, true);
- }
- }
- });
- }
- }
- break;
- case 1:
- {
- (void)SetFileReadOnlyWithRetry(FilePath, false);
- RemoveFileWithRetry(FilePath);
- }
- break;
- default:
- break;
- }
- }
- FileSizeIt++;
- }
- Work.Wait(5000, [&](bool IsAborted, bool IsPaused, std::ptrdiff_t PendingWork) {
- ZEN_UNUSED(IsAborted, IsPaused);
- ZEN_CONSOLE("Scrambling files, {} remaining", PendingWork);
- });
- ZEN_ASSERT(!AbortFlag.load());
- ZEN_CONSOLE("Scrambled files in {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
- };
+ if (SubOption == &m_AbortOptions)
+ {
+ ParseZenProcessId();
+ ZenState RunningState(m_ZenProcessId);
+ RunningState.StateData().Abort.store(true);
+ return 0;
+ }
- ScrambleDir(DownloadPath);
- ZEN_CONSOLE("\nRe-download Build {}, Part {} ({}) to '{}' (scrambled target)",
- BuildId,
- BuildPartId,
- m_BuildPartName,
- DownloadPath);
- DownloadFolder(Storage,
- BuildId,
- {BuildPartId},
- {},
- DownloadPath,
- DownloadPath / ZenFolderName,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- false,
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
- {
- ZEN_CONSOLE("Re-download failed. (scrambled target)");
- return 11;
- }
+ if (SubOption == &m_TestOptions)
+ {
+ m_SystemRootDir = (GetRunningExecutablePath().parent_path() / ".tmpzensystem").make_preferred();
+ CreateDirectories(m_SystemRootDir);
+ CleanDirectory(m_SystemRootDir, {});
+ auto _ = MakeGuard([&]() { DeleteDirectories(m_SystemRootDir); });
- ScrambleDir(DownloadPath);
+ ParsePath();
- Oid BuildId2 = Oid::NewOid();
- Oid BuildPartId2 = Oid::NewOid();
+ if (m_OverrideHost.empty() && m_StoragePath.empty())
+ {
+ m_StoragePath = (GetRunningExecutablePath().parent_path() / ".tmpstore").make_preferred();
+ CreateDirectories(m_StoragePath);
+ CleanDirectory(m_StoragePath, {});
+ m_StoragePath = m_StoragePath.generic_string();
+ }
- CbObject MetaData2 = MakeMetaData(BuildId2);
+ auto __ = MakeGuard([&]() {
+ if (m_OverrideHost.empty() && m_StoragePath.empty())
{
- ExtendableStringBuilder<256> SB;
- CompactBinaryToJson(MetaData, SB);
- ZEN_CONSOLE("\nUpload scrambled Build {}, Part {} ({})\n{}\n", BuildId2, BuildPartId2, m_BuildPartName, SB.ToView());
+ DeleteDirectories(m_StoragePath);
}
+ });
- UploadFolder(Storage,
- BuildId2,
- BuildPartId2,
- m_BuildPartName,
- DownloadPath,
- UploadTempDir,
- {},
- m_FindBlockMaxCount,
- m_BlockReuseMinPercentLimit,
- m_AllowMultiparts,
- MetaData2,
- true,
- false,
- true);
- if (AbortFlag)
- {
- ZEN_CONSOLE("Upload of scrambled failed.");
- return 11;
- }
+ BuildStorage::Statistics StorageStats;
+ BuildStorageCache::Statistics StorageCacheStats;
- ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}' (original)", BuildId, BuildPartId, m_BuildPartName, DownloadPath);
- DownloadFolder(Storage,
- BuildId,
- {BuildPartId},
- {},
- DownloadPath,
- DownloadPath / ZenFolderName,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- false,
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
- {
- ZEN_CONSOLE("Re-download failed.");
- return 11;
- }
+ const std::filesystem::path DownloadPath = m_Path.parent_path() / (m_BuildPartName + "_test");
+ const std::filesystem::path DownloadPath2 = m_Path.parent_path() / (m_BuildPartName + "_test2");
- ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}' (scrambled)", BuildId2, BuildPartId2, m_BuildPartName, DownloadPath);
- DownloadFolder(Storage,
- BuildId2,
- {BuildPartId2},
- {},
- DownloadPath,
- DownloadPath / ZenFolderName,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- false,
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
- {
- ZEN_CONSOLE("Re-download failed.");
- return 11;
- }
+ auto ___ = MakeGuard([DownloadPath, DownloadPath2]() {
+ CleanDirectory(DownloadPath, true);
+ DeleteDirectories(DownloadPath);
+ CleanDirectory(DownloadPath2, true);
+ DeleteDirectories(DownloadPath2);
+ });
- ZEN_CONSOLE("\nRe-download Build {}, Part {} ({}) to '{}' (scrambled)", BuildId2, BuildPartId2, m_BuildPartName, DownloadPath);
- DownloadFolder(Storage,
- BuildId2,
- {BuildPartId2},
- {},
- DownloadPath,
- DownloadPath / ZenFolderName,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- false,
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
+ if (m_ZenFolderPath.empty())
+ {
+ m_ZenFolderPath = m_Path / ZenFolderName;
+ }
+ MakeSafeAbsolutePathÍnPlace(m_ZenFolderPath);
+
+ StorageInstance Storage = CreateBuildStorage(StorageStats,
+ StorageCacheStats,
+ ZenTempFolderPath(m_ZenFolderPath),
+ /*RequriesNamespace*/ true,
+ /*RequireBucket*/ true);
+
+ m_BuildId = Oid::NewOid().ToString();
+ m_BuildPartName = m_Path.filename().string();
+ m_BuildPartId = Oid::NewOid().ToString();
+ m_CreateBuild = true;
+
+ const Oid BuildId = Oid::FromHexString(m_BuildId);
+ const Oid BuildPartId = Oid::FromHexString(m_BuildPartId);
+
+ auto MakeMetaData = [](const Oid& BuildId) -> CbObject {
+ CbObjectWriter BuildMetaDataWriter;
{
- ZEN_CONSOLE("Re-download failed.");
- return 11;
+ const uint32_t CL = BuildId.OidBits[2];
+ BuildMetaDataWriter.AddString("name", fmt::format("++Test+Main-CL-{}", CL));
+ BuildMetaDataWriter.AddString("branch", "ZenTestBuild");
+ BuildMetaDataWriter.AddString("baselineBranch", "ZenTestBuild");
+ BuildMetaDataWriter.AddString("platform", "Windows");
+ BuildMetaDataWriter.AddString("project", "Test");
+ BuildMetaDataWriter.AddInteger("changelist", CL);
+ BuildMetaDataWriter.AddString("buildType", "test-folder");
}
+ return BuildMetaDataWriter.Save();
+ };
+ CbObject MetaData = MakeMetaData(Oid::TryFromHexString(m_BuildId));
+ {
+ ExtendableStringBuilder<256> SB;
+ CompactBinaryToJson(MetaData, SB);
+ ZEN_CONSOLE("Upload Build {}, Part {} ({}) from '{}'\n{}", m_BuildId, BuildPartId, m_BuildPartName, m_Path, SB.ToView());
+ }
- ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}' (original)", BuildId, BuildPartId, m_BuildPartName, DownloadPath2);
- DownloadFolder(Storage,
- BuildId,
- {BuildPartId},
- {},
- DownloadPath2,
- DownloadPath2 / ZenFolderName,
- m_SystemRootDir,
- m_AllowMultiparts,
- m_AllowPartialBlockRequests,
- false,
- true,
- false,
- m_EnableScavenging,
- ""sv,
- ""sv);
- if (AbortFlag)
+ const std::filesystem::path UploadTempDir = UploadTempDirectory(m_Path);
+ // std::filesystem::path UploadTempDir = m_ZenFolderPath / "upload_tmp";
+
+ UploadFolder(Storage,
+ BuildId,
+ BuildPartId,
+ m_BuildPartName,
+ m_Path,
+ UploadTempDir,
+ {},
+ m_FindBlockMaxCount,
+ m_BlockReuseMinPercentLimit,
+ m_AllowMultiparts,
+ MetaData,
+ true,
+ false,
+ true);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Upload failed.");
+ return 11;
+ }
+
+ ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}'", BuildId, BuildPartId, m_BuildPartName, DownloadPath);
+ DownloadFolder(Storage,
+ BuildId,
+ {BuildPartId},
+ {},
+ DownloadPath,
+ DownloadPath / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ true,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Download failed.");
+ return 11;
+ }
+
+ ZEN_CONSOLE("\nRe-download Build {}, Part {} ({}) to '{}' (identical target)", BuildId, BuildPartId, m_BuildPartName, DownloadPath);
+ DownloadFolder(Storage,
+ BuildId,
+ {BuildPartId},
+ {},
+ DownloadPath,
+ DownloadPath / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ false,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Re-download failed. (identical target)");
+ return 11;
+ }
+
+ auto ScrambleDir = [](const std::filesystem::path& Path) {
+ ZEN_CONSOLE("\nScrambling '{}'", Path);
+ Stopwatch Timer;
+ DirectoryContent DownloadContent;
+ GetDirectoryContent(
+ Path,
+ DirectoryContentFlags::Recursive | DirectoryContentFlags::IncludeFiles | DirectoryContentFlags::IncludeFileSizes,
+ DownloadContent);
+ auto IsAcceptedFolder = [ExcludeFolders = DefaultExcludeFolders, Path](const std::filesystem::path& AbsolutePath) -> bool {
+ std::string RelativePath = std::filesystem::relative(AbsolutePath, Path).generic_string();
+ for (const std::string_view& ExcludeFolder : ExcludeFolders)
+ {
+ if (RelativePath.starts_with(ExcludeFolder))
+ {
+ if (RelativePath.length() == ExcludeFolder.length())
+ {
+ return false;
+ }
+ else if (RelativePath[ExcludeFolder.length()] == '/')
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ };
+
+ ParallelWork Work(AbortFlag, PauseFlag);
+
+ uint32_t Randomizer = 0;
+ auto FileSizeIt = DownloadContent.FileSizes.begin();
+ for (const std::filesystem::path& FilePath : DownloadContent.Files)
{
- ZEN_CONSOLE("Re-download failed.");
- return 11;
+ if (IsAcceptedFolder(FilePath))
+ {
+ uint32_t Case = (Randomizer++) % 7;
+ switch (Case)
+ {
+ case 0:
+ {
+ uint64_t SourceSize = *FileSizeIt;
+ if (SourceSize > 256)
+ {
+ Work.ScheduleWork(
+ GetIOWorkerPool(),
+ [SourceSize, FilePath = std::filesystem::path(FilePath)](std::atomic<bool>&) {
+ if (!AbortFlag)
+ {
+ bool IsReadOnly = SetFileReadOnlyWithRetry(FilePath, false);
+ {
+ BasicFile Source(FilePath, BasicFile::Mode::kWrite);
+ uint64_t RangeSize = Min(SourceSize / 3, 512u * 1024u);
+ IoBuffer TempBuffer1(RangeSize);
+ IoBuffer TempBuffer2(RangeSize);
+ IoBuffer TempBuffer3(RangeSize);
+ Source.Read(TempBuffer1.GetMutableView().GetData(), RangeSize, 0);
+ Source.Read(TempBuffer2.GetMutableView().GetData(), RangeSize, SourceSize / 2);
+ Source.Read(TempBuffer3.GetMutableView().GetData(), RangeSize, SourceSize - RangeSize);
+ Source.Write(TempBuffer1, SourceSize / 2);
+ Source.Write(TempBuffer2, SourceSize - RangeSize);
+ Source.Write(TempBuffer3, SourceSize - 0);
+ }
+ if (IsReadOnly)
+ {
+ SetFileReadOnly(FilePath, true);
+ }
+ }
+ });
+ }
+ }
+ break;
+ case 1:
+ {
+ (void)SetFileReadOnlyWithRetry(FilePath, false);
+ RemoveFileWithRetry(FilePath);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ FileSizeIt++;
}
+ Work.Wait(5000, [&](bool IsAborted, bool IsPaused, std::ptrdiff_t PendingWork) {
+ ZEN_UNUSED(IsAborted, IsPaused);
+ ZEN_CONSOLE("Scrambling files, {} remaining", PendingWork);
+ });
+ ZEN_ASSERT(!AbortFlag.load());
+ ZEN_CONSOLE("Scrambled files in {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
+ };
- return 0;
- }
- }
- catch (const std::system_error& SysErr)
- {
- if (IsOOD(SysErr))
+ ScrambleDir(DownloadPath);
+ ZEN_CONSOLE("\nRe-download Build {}, Part {} ({}) to '{}' (scrambled target)", BuildId, BuildPartId, m_BuildPartName, DownloadPath);
+ DownloadFolder(Storage,
+ BuildId,
+ {BuildPartId},
+ {},
+ DownloadPath,
+ DownloadPath / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ false,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
{
- ZEN_CONSOLE("Operation failed due to out of disk space: {}", SysErr.what());
- return 3;
+ ZEN_CONSOLE_ERROR("Re-download failed. (scrambled target)");
+ return 11;
}
- else if (IsOOM(SysErr))
+
+ ScrambleDir(DownloadPath);
+
+ Oid BuildId2 = Oid::NewOid();
+ Oid BuildPartId2 = Oid::NewOid();
+
+ CbObject MetaData2 = MakeMetaData(BuildId2);
{
- ZEN_CONSOLE("Operation failed due to out of memory: {}", SysErr.what());
- return 3;
+ ExtendableStringBuilder<256> SB;
+ CompactBinaryToJson(MetaData, SB);
+ ZEN_CONSOLE("\nUpload scrambled Build {}, Part {} ({})\n{}\n", BuildId2, BuildPartId2, m_BuildPartName, SB.ToView());
}
- else
+
+ UploadFolder(Storage,
+ BuildId2,
+ BuildPartId2,
+ m_BuildPartName,
+ DownloadPath,
+ UploadTempDir,
+ {},
+ m_FindBlockMaxCount,
+ m_BlockReuseMinPercentLimit,
+ m_AllowMultiparts,
+ MetaData2,
+ true,
+ false,
+ true);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Upload of scrambled failed.");
+ return 11;
+ }
+
+ ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}' (original)", BuildId, BuildPartId, m_BuildPartName, DownloadPath);
+ DownloadFolder(Storage,
+ BuildId,
+ {BuildPartId},
+ {},
+ DownloadPath,
+ DownloadPath / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ false,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Re-download failed.");
+ return 11;
+ }
+
+ ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}' (scrambled)", BuildId2, BuildPartId2, m_BuildPartName, DownloadPath);
+ DownloadFolder(Storage,
+ BuildId2,
+ {BuildPartId2},
+ {},
+ DownloadPath,
+ DownloadPath / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ false,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Re-download failed.");
+ return 11;
+ }
+
+ ZEN_CONSOLE("\nRe-download Build {}, Part {} ({}) to '{}' (scrambled)", BuildId2, BuildPartId2, m_BuildPartName, DownloadPath);
+ DownloadFolder(Storage,
+ BuildId2,
+ {BuildPartId2},
+ {},
+ DownloadPath,
+ DownloadPath / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ false,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
{
- ZEN_ERROR("{}", SysErr.what());
- return 3;
+ ZEN_CONSOLE_ERROR("Re-download failed.");
+ return 11;
+ }
+
+ ZEN_CONSOLE("\nDownload Build {}, Part {} ({}) to '{}' (original)", BuildId, BuildPartId, m_BuildPartName, DownloadPath2);
+ DownloadFolder(Storage,
+ BuildId,
+ {BuildPartId},
+ {},
+ DownloadPath2,
+ DownloadPath2 / ZenFolderName,
+ m_SystemRootDir,
+ m_AllowMultiparts,
+ m_AllowPartialBlockRequests,
+ false,
+ true,
+ false,
+ m_EnableScavenging,
+ ""sv,
+ ""sv);
+ if (AbortFlag)
+ {
+ ZEN_CONSOLE_ERROR("Re-download failed.");
+ return 11;
}
- }
- catch (const HttpClientError& HttpEx)
- {
- ZEN_CONSOLE("Operation failed: {}", HttpEx.what());
- return HttpEx.m_Error != 0 ? HttpEx.m_Error : (int)HttpEx.m_ResponseCode;
- }
- catch (const std::exception& Ex)
- {
- ZEN_ERROR("{}", Ex.what());
- return 3;
+
+ return 0;
}
ZEN_ASSERT(false);
}
diff --git a/src/zen/cmds/cache_cmd.cpp b/src/zen/cmds/cache_cmd.cpp
index 4412eaf34..90f428b29 100644
--- a/src/zen/cmds/cache_cmd.cpp
+++ b/src/zen/cmds/cache_cmd.cpp
@@ -115,11 +115,11 @@ DropCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Result.status_code)
{
- ZEN_ERROR("Drop failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("Drop failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("Drop failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("Drop failed: {}", Result.error.message);
}
return 1;
@@ -217,11 +217,11 @@ CacheInfoCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Result.status_code)
{
- ZEN_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("Info failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("Info failed: {}", Result.error.message);
}
return 1;
@@ -267,11 +267,11 @@ CacheStatsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv
if (Result.status_code)
{
- ZEN_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("Info failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("Info failed: {}", Result.error.message);
}
return 1;
@@ -336,9 +336,7 @@ CacheDetailsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** ar
{
if (m_Namespace.empty() || m_Bucket.empty())
{
- ZEN_ERROR("Provide namespace and bucket name");
- ZEN_CONSOLE("{}", m_Options.help({""}).c_str());
- return 1;
+ throw OptionParseException("Provide namespace and bucket name");
}
Session.SetUrl({fmt::format("{}/z$/details$/{}/{}/{}", m_HostName, m_Namespace, m_Bucket, m_ValueKey)});
}
@@ -346,9 +344,7 @@ CacheDetailsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** ar
{
if (m_Namespace.empty())
{
- ZEN_ERROR("Provide namespace name");
- ZEN_CONSOLE("{}", m_Options.help({""}).c_str());
- return 1;
+ throw OptionParseException("Provide namespace name");
}
Session.SetUrl({fmt::format("{}/z$/details$/{}/{}", m_HostName, m_Namespace, m_Bucket)});
}
@@ -373,11 +369,11 @@ CacheDetailsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** ar
if (Result.status_code)
{
- ZEN_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ ZEN_CONSOLE_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
}
else
{
- ZEN_ERROR("Info failed: {}", Result.error.message);
+ ZEN_CONSOLE_ERROR("Info failed: {}", Result.error.message);
}
return 1;
diff --git a/src/zen/cmds/copy_cmd.cpp b/src/zen/cmds/copy_cmd.cpp
index e86b6964c..4e54f27bb 100644
--- a/src/zen/cmds/copy_cmd.cpp
+++ b/src/zen/cmds/copy_cmd.cpp
@@ -147,7 +147,7 @@ CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
++FailedFileCount;
- ZEN_CONSOLE_ERROR("failed to copy '{}' to '{}': '{}'", FromPath, ToPath, Ex.what());
+ ZEN_CONSOLE_ERROR("Failed to copy '{}' to '{}': '{}'", FromPath, ToPath, Ex.what());
}
}
}
@@ -208,7 +208,7 @@ CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE_ERROR("Error: failed to copy '{}' to '{}': '{}'", FromPath, ToPath, Ex.what());
+ ZEN_CONSOLE_ERROR("Failed to copy '{}' to '{}': '{}'", FromPath, ToPath, Ex.what());
return 1;
}
diff --git a/src/zen/cmds/dedup_cmd.cpp b/src/zen/cmds/dedup_cmd.cpp
index 5f74305c7..033ac87c3 100644
--- a/src/zen/cmds/dedup_cmd.cpp
+++ b/src/zen/cmds/dedup_cmd.cpp
@@ -68,15 +68,13 @@ DedupCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (!SourceGood)
{
- ZEN_ERROR("Source directory '{}' does not support deduplication", m_DedupSource);
-
+ ZEN_CONSOLE_ERROR("Source directory '{}' does not support deduplication", m_DedupSource);
return 0;
}
if (!TargetGood)
{
- ZEN_ERROR("Target directory '{}' does not support deduplication", m_DedupTarget);
-
+ ZEN_CONSOLE_ERROR("Target directory '{}' does not support deduplication", m_DedupTarget);
return 0;
}
diff --git a/src/zen/cmds/info_cmd.cpp b/src/zen/cmds/info_cmd.cpp
index 73a5d2e5d..8e0b3d663 100644
--- a/src/zen/cmds/info_cmd.cpp
+++ b/src/zen/cmds/info_cmd.cpp
@@ -44,6 +44,10 @@ InfoCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
ZEN_CONSOLE("{}", Result.ToText());
}
+ else
+ {
+ Result.ThrowError(fmt::format("Failed getting info from {}", m_HostName));
+ }
return 0;
}
diff --git a/src/zen/cmds/print_cmd.cpp b/src/zen/cmds/print_cmd.cpp
index 5bc8a8ed8..fd6d92f28 100644
--- a/src/zen/cmds/print_cmd.cpp
+++ b/src/zen/cmds/print_cmd.cpp
@@ -84,7 +84,7 @@ PrintCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Fc.ErrorCode)
{
- ZEN_ERROR("Failed to read file '{}': {}", m_Filename, Fc.ErrorCode.message());
+ ZEN_CONSOLE_ERROR("Failed to read file '{}': {}", m_Filename, Fc.ErrorCode.message());
return 1;
}
@@ -149,7 +149,7 @@ PrintCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (FilteredResult == CbValidateError::None && FilteredResult != Result)
{
- ZEN_WARN(
+ ZEN_CONSOLE_WARN(
"Object in package message file '{}' does not appear to be an optimal compact binary format (validation error {:#x}: '{}')",
m_Filename,
uint32_t(Result),
@@ -158,10 +158,10 @@ PrintCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (FilteredResult != CbValidateError::None)
{
- ZEN_ERROR("Object in package message file '{}' does not appear to be compact binary (validation error {:#x}: '{}')",
- m_Filename,
- uint32_t(FilteredResult),
- ToString(FilteredResult));
+ ZEN_CONSOLE_ERROR("Object in package message file '{}' does not appear to be compact binary (validation error {:#x}: '{}')",
+ m_Filename,
+ uint32_t(FilteredResult),
+ ToString(FilteredResult));
return 1;
}
else
@@ -177,18 +177,18 @@ PrintCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (FilteredResult == CbValidateError::None && FilteredResult != Result)
{
- ZEN_WARN("Data in file '{}' does not appear to be an optimal compact binary format (validation error {:#x}: '{}')",
- m_Filename,
- uint32_t(Result),
- ToString(Result));
+ ZEN_CONSOLE_WARN("Data in file '{}' does not appear to be an optimal compact binary format (validation error {:#x}: '{}')",
+ m_Filename,
+ uint32_t(Result),
+ ToString(Result));
}
if (FilteredResult != CbValidateError::None)
{
- ZEN_ERROR("Data in file '{}' does not appear to be compact binary (validation error {:#x}: '{}')",
- m_Filename,
- uint32_t(FilteredResult),
- ToString(FilteredResult));
+ ZEN_CONSOLE_ERROR("Data in file '{}' does not appear to be compact binary (validation error {:#x}: '{}')",
+ m_Filename,
+ uint32_t(FilteredResult),
+ ToString(FilteredResult));
return 1;
}
else
diff --git a/src/zen/cmds/projectstore_cmd.cpp b/src/zen/cmds/projectstore_cmd.cpp
index f919edc87..5f0f52f7c 100644
--- a/src/zen/cmds/projectstore_cmd.cpp
+++ b/src/zen/cmds/projectstore_cmd.cpp
@@ -449,7 +449,7 @@ namespace {
}
else
{
- ZEN_CONSOLE("Unable to resolve project name '{}', no projects found at {}", OptionalProjectName, Http.GetBaseUri());
+ ZEN_CONSOLE_WARN("Unable to resolve project name '{}', no projects found at {}", OptionalProjectName, Http.GetBaseUri());
}
return {};
}
@@ -470,10 +470,10 @@ namespace {
std::vector<std::string> MatchingProjectIds = MatchId(AvailableProjects, OptionalProjectName);
if (MatchingProjectIds.empty())
{
- ZEN_CONSOLE("Unable to match project name '{}' at {}, available projects: {}",
- OptionalProjectName,
- Http.GetBaseUri(),
- FmtProjectIdArray(AvailableProjects));
+ ZEN_CONSOLE_WARN("Unable to match project name '{}' at {}, available projects: {}",
+ OptionalProjectName,
+ Http.GetBaseUri(),
+ FmtProjectIdArray(AvailableProjects));
return {};
}
@@ -482,10 +482,10 @@ namespace {
return MatchingProjectIds.front();
}
- ZEN_CONSOLE("Project name is ambigous '{}' at {}: possible matches: {}",
- OptionalProjectName,
- Http.GetBaseUri(),
- FmtProjectIdArray(MatchingProjectIds));
+ ZEN_CONSOLE_WARN("Project name is ambigous '{}' at {}: possible matches: {}",
+ OptionalProjectName,
+ Http.GetBaseUri(),
+ FmtProjectIdArray(MatchingProjectIds));
return {};
}
@@ -500,10 +500,10 @@ namespace {
}
else
{
- ZEN_CONSOLE("Unable to resolve oplog name '{}' for project '{}', no oplogs found at {}",
- OptionalOplogName,
- ProjectName,
- Http.GetBaseUri());
+ ZEN_CONSOLE_WARN("Unable to resolve oplog name '{}' for project '{}', no oplogs found at {}",
+ OptionalOplogName,
+ ProjectName,
+ Http.GetBaseUri());
}
return {};
}
@@ -524,11 +524,11 @@ namespace {
std::vector<std::string> MatchingOplogIds = MatchId(AvailableOplogs, OptionalOplogName);
if (MatchingOplogIds.empty())
{
- ZEN_CONSOLE("Unable to match oplog name '{}' for project '{}', available oplogs at {}: {}",
- OptionalOplogName,
- ProjectName,
- Http.GetBaseUri(),
- FmtArray(AvailableOplogs));
+ ZEN_CONSOLE_WARN("Unable to match oplog name '{}' for project '{}', available oplogs at {}: {}",
+ OptionalOplogName,
+ ProjectName,
+ Http.GetBaseUri(),
+ FmtArray(AvailableOplogs));
return {};
}
@@ -537,11 +537,11 @@ namespace {
return MatchingOplogIds.front();
}
- ZEN_CONSOLE("Oplog name '{}' for project '{}' at {}, is ambigous, possible matches: {}",
- OptionalOplogName,
- ProjectName,
- Http.GetBaseUri(),
- FmtArray(MatchingOplogIds));
+ ZEN_CONSOLE_WARN("Oplog name '{}' for project '{}' at {}, is ambigous, possible matches: {}",
+ OptionalOplogName,
+ ProjectName,
+ Http.GetBaseUri(),
+ FmtArray(MatchingOplogIds));
return {};
}
@@ -766,8 +766,7 @@ CreateProjectCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** a
if (m_ProjectId.empty())
{
- ZEN_ERROR("Project name must be given");
- return 1;
+ throw OptionParseException("Project name must be given");
}
HttpClient Http(m_HostName);
@@ -778,7 +777,7 @@ CreateProjectCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** a
{
if (HttpClient::Response Result = Http.Get(Url, HttpClient::Accept(ZenContentType::kJSON)))
{
- ZEN_CONSOLE("Project already exists.\n{}", Result.ToText());
+ ZEN_CONSOLE_ERROR("Project already exists.\n{}", Result.ToText());
return 1;
}
}
@@ -1073,9 +1072,7 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
{
if (m_JupiterNamespace.empty() || m_JupiterBucket.empty())
{
- ZEN_ERROR("Options for cloud target are missing");
- ZEN_CONSOLE("{}", m_Options.help({"cloud"}).c_str());
- return 1;
+ throw OptionParseException("Options for cloud target are missing");
}
if (m_CloudKey.empty())
{
@@ -1088,23 +1085,21 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (!m_BuildsUrl.empty())
{
+ if (m_JupiterNamespace.empty())
+ {
+ throw OptionParseException("Namespace for builds target it missing");
+ }
if (m_JupiterNamespace.empty() || m_JupiterBucket.empty())
{
- ZEN_ERROR("Options for builds target are missing");
- ZEN_CONSOLE("{}", m_Options.help({"builds"}).c_str());
- return 1;
+ throw OptionParseException("Bucket for builds target it missing");
}
if (m_BuildsMetadataPath.empty() && m_BuildsMetadata.empty())
{
- ZEN_ERROR("Options for builds target are missing");
- ZEN_CONSOLE("{}", m_Options.help({"builds"}).c_str());
- return 1;
+ throw OptionParseException("Options for builds target metadata are missing");
}
if (!m_BuildsMetadataPath.empty() && !m_BuildsMetadata.empty())
{
- ZEN_ERROR("Conflicting options for builds target");
- ZEN_CONSOLE("{}", m_Options.help({"builds"}).c_str());
- return 1;
+ throw OptionParseException("Conflicting options for builds target metadata");
}
if (m_BuildsId.empty())
{
@@ -1118,12 +1113,12 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (m_ZenProjectName.empty())
{
m_ZenProjectName = m_ProjectName;
- ZEN_WARN("Using default zen target project id '{}'", m_ZenProjectName);
+ ZEN_CONSOLE_WARN("Using default zen target project id '{}'", m_ZenProjectName);
}
if (m_ZenOplogName.empty())
{
m_ZenOplogName = m_OplogName;
- ZEN_WARN("Using default zen target oplog id '{}'", m_ZenOplogName);
+ ZEN_CONSOLE_WARN("Using default zen target oplog id '{}'", m_ZenOplogName);
}
std::string TargetUrlBase = m_ZenUrl;
@@ -1141,7 +1136,7 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
{
if (m_ZenClean)
{
- ZEN_WARN("Deleting zen remote oplog '{}/{}'", m_ZenProjectName, m_ZenOplogName)
+ ZEN_CONSOLE_WARN("Deleting zen remote oplog '{}/{}'", m_ZenProjectName, m_ZenOplogName);
Result = TargetHttp.Delete(Url, HttpClient::Accept(ZenContentType::kJSON));
if (!Result)
{
@@ -1163,7 +1158,7 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (CreateOplog)
{
- ZEN_WARN("Creating zen remote oplog '{}/{}'", m_ZenProjectName, m_ZenOplogName);
+ ZEN_CONSOLE_WARN("Creating zen remote oplog '{}/{}'", m_ZenProjectName, m_ZenOplogName);
if (HttpClient::Response Result = TargetHttp.Post(Url); !Result)
{
Result.ThrowError("failed creating zen remote oplog"sv);
@@ -1177,7 +1172,7 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (m_FileName.empty())
{
m_FileName = m_OplogName;
- ZEN_WARN("Using default file name '{}'", m_FileName);
+ ZEN_CONSOLE_WARN("Using default file name '{}'", m_FileName);
}
}
@@ -1370,21 +1365,11 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
m_PlainProgress);
}
}
- catch (const HttpClientError& Ex)
- {
- ZEN_CONSOLE("Oplog export failed: '{}'", Ex.what());
- return Ex.m_Error != 0 ? Ex.m_Error : (int)Ex.m_ResponseCode;
- }
catch (const AsyncJobError& Ex)
{
- ZEN_CONSOLE("Oplog export failed: '{}'", Ex.what());
+ ZEN_CONSOLE_ERROR("Oplog export failed: '{}'", Ex.what());
return Ex.m_ReturnCode;
}
- catch (const std::exception& Ex)
- {
- ZEN_CONSOLE("Oplog export failed: '{}'", Ex.what());
- return 1;
- }
return 0;
}
@@ -1498,14 +1483,12 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (m_ProjectName.empty())
{
- ZEN_ERROR("Project name must be given");
- return 1;
+ throw OptionParseException("Project name must be given");
}
if (m_OplogName.empty())
{
- ZEN_ERROR("Oplog name must be given");
- return 1;
+ throw OptionParseException("Oplog name must be given");
}
HttpClient Http(m_HostName);
@@ -1522,35 +1505,41 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
TargetCount += m_FileDirectoryPath.empty() ? 0 : 1;
if (TargetCount != 1)
{
- ZEN_ERROR("Provide one source only");
- ZEN_CONSOLE("{}", m_Options.help({""}).c_str());
- return 1;
+ throw OptionParseException("Provide one source only");
}
if (!m_CloudUrl.empty())
{
- if (m_JupiterNamespace.empty() || m_JupiterBucket.empty())
+ if (m_JupiterNamespace.empty())
{
- ZEN_ERROR("Options for cloud source are missing");
- ZEN_CONSOLE("{}", m_Options.help({"cloud"}).c_str());
- return 1;
+ throw OptionParseException("Namespace option for cloud source is missing");
+ }
+ if (m_JupiterBucket.empty())
+ {
+ throw OptionParseException("Bucket option for cloud source is missing");
}
if (m_CloudKey.empty())
{
std::string KeyString = fmt::format("{}/{}/{}/{}", m_ProjectName, m_OplogName, m_JupiterNamespace, m_JupiterBucket);
IoHash Key = IoHash::HashBuffer(KeyString.data(), KeyString.size());
m_CloudKey = Key.ToHexString();
- ZEN_WARN("Using auto generated cloud key '{}'", m_CloudKey);
+ ZEN_CONSOLE_WARN("Using auto generated cloud key '{}'", m_CloudKey);
}
}
if (!m_BuildsUrl.empty())
{
- if (m_JupiterNamespace.empty() || m_JupiterBucket.empty() || m_BuildsId.empty())
+ if (m_JupiterNamespace.empty())
{
- ZEN_ERROR("Options for builds source are missing");
- ZEN_CONSOLE("{}", m_Options.help({"builds"}).c_str());
- return 1;
+ throw OptionParseException("Namespace option for builds source is missing");
+ }
+ if (m_JupiterBucket.empty())
+ {
+ throw OptionParseException("Bucket option for builds source is missing");
+ }
+ if (m_BuildsId.empty())
+ {
+ throw OptionParseException("Build id option for builds source is missing");
}
}
@@ -1559,12 +1548,12 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (m_ZenProjectName.empty())
{
m_ZenProjectName = m_ProjectName;
- ZEN_WARN("Using default zen target project id '{}'", m_ZenProjectName);
+ ZEN_CONSOLE_WARN("Using default zen target project id '{}'", m_ZenProjectName);
}
if (m_ZenOplogName.empty())
{
m_ZenOplogName = m_OplogName;
- ZEN_WARN("Using default zen target oplog id '{}'", m_ZenOplogName);
+ ZEN_CONSOLE_WARN("Using default zen target oplog id '{}'", m_ZenOplogName);
}
}
@@ -1573,7 +1562,7 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (m_FileName.empty())
{
m_FileName = m_OplogName;
- ZEN_WARN("Using auto generated file name '{}'", m_FileName);
+ ZEN_CONSOLE_WARN("Using auto generated file name '{}'", m_FileName);
}
}
@@ -1598,7 +1587,7 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
{
OplogPayload = MakeCbObjectPayload([&](CbObjectWriter& Writer) { Writer.AddString("gcpath"sv, m_GcPath); });
}
- ZEN_WARN("Creating oplog '{}/{}'", m_ProjectName, m_OplogName);
+ ZEN_CONSOLE("Creating oplog '{}/{}'", m_ProjectName, m_OplogName);
if (HttpClient::Response Result = Http.Post(Url, OplogPayload); !Result)
{
Result.ThrowError("failed creating oplog"sv);
@@ -1723,21 +1712,11 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
m_PlainProgress);
}
}
- catch (const HttpClientError& Ex)
- {
- ZEN_CONSOLE("Oplog import failed: '{}'", Ex.what());
- return Ex.m_Error != 0 ? Ex.m_Error : (int)Ex.m_ResponseCode;
- }
catch (const AsyncJobError& Ex)
{
- ZEN_CONSOLE("Oplog export failed: '{}'", Ex.what());
+ ZEN_CONSOLE_ERROR("Oplog export failed: '{}'", Ex.what());
return Ex.m_ReturnCode;
}
- catch (const std::exception& Ex)
- {
- ZEN_CONSOLE("Oplog import failed: '{}'", Ex.what());
- return 1;
- }
return 0;
}
@@ -1780,7 +1759,7 @@ SnapshotOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** a
if (m_ProjectName.empty())
{
- ZEN_ERROR("Project name must be given");
+ throw OptionParseException("Project name must be given");
return 1;
}
@@ -2147,7 +2126,7 @@ OplogMirrorCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
catch (const std::exception& Ex)
{
AbortFlag.store(true);
- ZEN_CONSOLE("Failed writing file to '{}'. Reason: '{}'", TargetPath, Ex.what());
+ ZEN_CONSOLE_ERROR("Failed writing file to '{}'. Reason: '{}'", TargetPath, Ex.what());
}
}
});
@@ -2233,7 +2212,7 @@ OplogMirrorCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
}
else
{
- ZEN_ERROR("unknown format response to oplog entries request");
+ ZEN_CONSOLE_ERROR("Unknown format response to oplog entries request");
}
}
else
diff --git a/src/zen/cmds/rpcreplay_cmd.cpp b/src/zen/cmds/rpcreplay_cmd.cpp
index 4fc38d92a..6c26eaf23 100644
--- a/src/zen/cmds/rpcreplay_cmd.cpp
+++ b/src/zen/cmds/rpcreplay_cmd.cpp
@@ -429,7 +429,7 @@ RpcReplayCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Response.error || !(IsHttpSuccessCode(Response.status_code) ||
Response.status_code == gsl::narrow<long>(HttpResponseCode::NotFound)))
{
- ZEN_CONSOLE("{}", FormatHttpResponse(Response));
+ ZEN_CONSOLE_ERROR("{}", FormatHttpResponse(Response));
break;
}
BytesReceived.fetch_add(Response.downloaded_bytes);
diff --git a/src/zen/cmds/serve_cmd.cpp b/src/zen/cmds/serve_cmd.cpp
index 64039e4c9..cfaa12bc0 100644
--- a/src/zen/cmds/serve_cmd.cpp
+++ b/src/zen/cmds/serve_cmd.cpp
@@ -93,7 +93,7 @@ ServeCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE("failed to spawn server on port {}: '{}'", ServerPort, Ex.what());
+ ZEN_CONSOLE_ERROR("Failed to spawn server on port {}: '{}'", ServerPort, Ex.what());
throw zen::OptionParseException("unable to resolve server specification (even after spawning server)");
}
@@ -111,7 +111,7 @@ ServeCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (ServerInstance)
{
m_HostName = ServerInstance->GetBaseUri();
- ZEN_CONSOLE("base uri: {}", m_HostName);
+ ZEN_CONSOLE("Base uri: {}", m_HostName);
}
// Generate manifest for tree
@@ -159,7 +159,7 @@ ServeCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
for (const FsVisitor::FileEntry& Entry : Visitor.Files)
{
- ZEN_CONSOLE("file: {}", Entry.FilePath);
+ ZEN_CONSOLE("File: {}", Entry.FilePath);
Cbo.BeginObject();
@@ -225,12 +225,10 @@ ServeCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (!HttpResponse)
{
- ZEN_CONSOLE("error: failed to append manifest!");
-
- return 1;
+ HttpResponse.ThrowError("Failed to append manifest");
}
- ZEN_CONSOLE("ok serving files now");
+ ZEN_CONSOLE("Ok serving files now");
#if ZEN_PLATFORM_WINDOWS
_getch(); // TEMPORARY HACK
diff --git a/src/zen/cmds/status_cmd.cpp b/src/zen/cmds/status_cmd.cpp
index 2b507e43d..b5764af44 100644
--- a/src/zen/cmds/status_cmd.cpp
+++ b/src/zen/cmds/status_cmd.cpp
@@ -34,14 +34,14 @@ StatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
if (!IsFile(m_DataDir / ".lock"))
{
- ZEN_CONSOLE("lock file does not exist in directory '{}'", m_DataDir);
+ ZEN_CONSOLE_ERROR("Lock file does not exist in directory '{}'", m_DataDir);
return 1;
}
LockFileInfo Info = ReadLockFilePayload(LoadCompactBinaryObject(IoBufferBuilder::MakeFromFile(m_DataDir / ".lock")));
std::string Reason;
if (!ValidateLockFileInfo(Info, Reason))
{
- ZEN_CONSOLE("lock file in directory '{}' is not valid. Reason: '{}'", m_DataDir, Reason);
+ ZEN_CONSOLE_ERROR("Lock file in directory '{}' is not valid. Reason: '{}'", m_DataDir, Reason);
return 1;
}
EffectivePort = Info.EffectiveListenPort;
@@ -50,8 +50,7 @@ StatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
ZenServerState State;
if (!State.InitializeReadOnly())
{
- ZEN_CONSOLE("no Zen state found");
-
+ ZEN_CONSOLE("No Zen state found");
return 0;
}
diff --git a/src/zen/cmds/top_cmd.cpp b/src/zen/cmds/top_cmd.cpp
index 568ee76c9..9794dc1c0 100644
--- a/src/zen/cmds/top_cmd.cpp
+++ b/src/zen/cmds/top_cmd.cpp
@@ -27,7 +27,7 @@ TopCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
ZenServerState State;
if (!State.InitializeReadOnly())
{
- ZEN_CONSOLE("no Zen state found");
+ ZEN_CONSOLE("No Zen state found");
return 0;
}
@@ -75,7 +75,7 @@ PsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
ZenServerState State;
if (!State.InitializeReadOnly())
{
- ZEN_CONSOLE("no Zen state found");
+ ZEN_CONSOLE("No Zen state found");
return 0;
}
diff --git a/src/zen/cmds/trace_cmd.cpp b/src/zen/cmds/trace_cmd.cpp
index dacc13ebf..85caf33b8 100644
--- a/src/zen/cmds/trace_cmd.cpp
+++ b/src/zen/cmds/trace_cmd.cpp
@@ -48,7 +48,7 @@ TraceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_ERROR("trace stop failed: {}", Response.ToText());
+ ZEN_CONSOLE_ERROR("trace stop failed: {}", Response.ToText());
return 1;
}
}
@@ -72,7 +72,7 @@ TraceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_ERROR("trace start failed: {}", Response.ToText());
+ ZEN_CONSOLE_ERROR("trace start failed: {}", Response.ToText());
return 1;
}
}
@@ -84,7 +84,7 @@ TraceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_ERROR("trace status failed: {}", Response.ToText());
+ ZEN_CONSOLE_ERROR("trace status failed: {}", Response.ToText());
}
return 1;
diff --git a/src/zen/cmds/up_cmd.cpp b/src/zen/cmds/up_cmd.cpp
index d0763701e..fd330f616 100644
--- a/src/zen/cmds/up_cmd.cpp
+++ b/src/zen/cmds/up_cmd.cpp
@@ -98,7 +98,7 @@ UpCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
if (Server.IsRunning())
{
- ZEN_ERROR("zen server launch failed (timed out), terminating");
+ ZEN_CONSOLE_ERROR("Zen server launch failed (timed out), terminating");
Server.Terminate();
if (!m_ShowConsole)
{
@@ -121,7 +121,7 @@ UpCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_CONSOLE("zen server up");
+ ZEN_CONSOLE("Zen server up");
}
}
return 0;
@@ -157,14 +157,14 @@ AttachCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
if (!IsFile(m_DataDir / ".lock"))
{
- ZEN_CONSOLE("lock file does not exist in directory '{}'", m_DataDir);
+ ZEN_CONSOLE("Lock file does not exist in directory '{}'", m_DataDir);
return 1;
}
LockFileInfo Info = ReadLockFilePayload(LoadCompactBinaryObject(IoBufferBuilder::MakeFromFile(m_DataDir / ".lock")));
std::string Reason;
if (!ValidateLockFileInfo(Info, Reason))
{
- ZEN_CONSOLE("lock file in directory '{}' is not valid. Reason: '{}'", m_DataDir, Reason);
+ ZEN_CONSOLE("Lock file in directory '{}' is not valid. Reason: '{}'", m_DataDir, Reason);
return 1;
}
Entry = Instance.LookupByEffectivePort(Info.EffectiveListenPort);
@@ -172,18 +172,18 @@ AttachCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (!Entry)
{
- ZEN_WARN("no zen server instance to add sponsor process to");
+ ZEN_CONSOLE_ERROR("No zen server instance to add sponsor process to");
return 1;
}
// Sponsor processes are checked every second, so 2 second wait time should be enough
if (!Entry->AddSponsorProcess(m_OwnerPid, 2000))
{
- ZEN_WARN("unable to add sponsor process to running zen server instance");
+ ZEN_CONSOLE_ERROR("Unable to add sponsor process to running zen server instance");
return 1;
}
- ZEN_CONSOLE("added sponsor process {} to running instance {} on port {}", m_OwnerPid, Entry->Pid.load(), m_Port);
+ ZEN_CONSOLE("Added sponsor process {} to running instance {} on port {}", m_OwnerPid, Entry->Pid.load(), m_Port);
return 0;
}
@@ -224,14 +224,14 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
if (!IsFile(m_DataDir / ".lock"))
{
- ZEN_CONSOLE("lock file does not exist in directory '{}'", m_DataDir);
+ ZEN_CONSOLE_ERROR("Lock file does not exist in directory '{}'", m_DataDir);
return 1;
}
LockFileInfo Info = ReadLockFilePayload(LoadCompactBinaryObject(IoBufferBuilder::MakeFromFile(m_DataDir / ".lock")));
std::string Reason;
if (!ValidateLockFileInfo(Info, Reason))
{
- ZEN_CONSOLE("lock file in directory '{}' is not valid. Reason: '{}'", m_DataDir, Reason);
+ ZEN_CONSOLE_ERROR("Lock file in directory '{}' is not valid. Reason: '{}'", m_DataDir, Reason);
return 1;
}
Entry = Instance.LookupByEffectivePort(Info.EffectiveListenPort);
@@ -272,7 +272,7 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else if (Ec)
{
- ZEN_CONSOLE("requesting shutdown of server on port {} failed. Reason: '{}'", EntryPort, Ec.message());
+ ZEN_CONSOLE_WARN("Requesting shutdown of server on port {} failed. Reason: '{}'", EntryPort, Ec.message());
}
}
catch (const std::exception& Ex)
@@ -284,7 +284,7 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
// handle to determine when the server has shut down. Thus we signal that we would like
// a shutdown via the shutdown flag and the check if the entry is still running.
- ZEN_CONSOLE("requesting detached shutdown of server on port {}", EntryPort);
+ ZEN_CONSOLE("Requesting detached shutdown of server on port {}", EntryPort);
Entry->SignalShutdownRequest();
Stopwatch Timer;
@@ -294,12 +294,12 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
Entry = Instance.Lookup(EntryPort);
if (Entry == nullptr)
{
- ZEN_CONSOLE("shutdown complete");
+ ZEN_CONSOLE("Shutdown complete");
return 0;
}
if (Entry->Pid.load() != ServerProcessPid)
{
- ZEN_CONSOLE("shutdown complete");
+ ZEN_CONSOLE("Shutdown complete");
return 0;
}
Sleep(100);
@@ -313,35 +313,36 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
ProcessHandle RunningProcess;
if (std::error_code Ec = FindProcess(ServerExePath, RunningProcess); !Ec, /*IncludeSelf*/ false)
{
- ZEN_WARN("attempting hard terminate of zen process with pid ({})", RunningProcess.Pid());
+ ZEN_CONSOLE_WARN("Attempting hard terminate of zen process with pid ({})", RunningProcess.Pid());
try
{
if (RunningProcess.Terminate(0))
{
- ZEN_CONSOLE("terminate complete");
+ ZEN_CONSOLE("Terminate complete");
return 0;
}
- ZEN_CONSOLE("failed to terminate server, still running");
+ ZEN_CONSOLE_ERROR("Failed to terminate server, still running");
return 1;
}
catch (const std::exception& Ex)
{
- ZEN_CONSOLE("failed to terminate server: '{}'", Ex.what());
+ ZEN_CONSOLE_ERROR("Failed to terminate server: '{}'", Ex.what());
return 1;
}
}
else
{
- ZEN_CONSOLE("Failed to find process '{}', reason: {}", ServerExePath.string(), Ec.message());
+ ZEN_CONSOLE_WARN("Failed to find process '{}', reason: {}", ServerExePath.string(), Ec.message());
}
}
else if (Entry)
{
- ZEN_CONSOLE("failed to shutdown of server on port {}, use --force to hard terminate process", Entry->DesiredListenPort.load());
+ ZEN_CONSOLE_ERROR("Failed to shutdown of server on port {}, use --force to hard terminate process",
+ Entry->DesiredListenPort.load());
return 1;
}
- ZEN_CONSOLE("no zen server to bring down");
+ ZEN_CONSOLE("No zen server to bring down");
return 0;
}
diff --git a/src/zen/cmds/version_cmd.cpp b/src/zen/cmds/version_cmd.cpp
index 7dfa125e4..1be02331d 100644
--- a/src/zen/cmds/version_cmd.cpp
+++ b/src/zen/cmds/version_cmd.cpp
@@ -72,7 +72,7 @@ VersionCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
HttpClient::Response Response = Client.Get(VersionRequest, {}, Parameters);
if (!Response.IsSuccess())
{
- ZEN_ERROR("{} failed: {}", VersionRequest, Response.ErrorMessage(""sv));
+ ZEN_CONSOLE_ERROR("{} failed: {}", VersionRequest, Response.ErrorMessage(""sv));
return 1;
}
Version = Response.AsText();
diff --git a/src/zen/cmds/wipe_cmd.cpp b/src/zen/cmds/wipe_cmd.cpp
index fcc18df2b..5a9d0174e 100644
--- a/src/zen/cmds/wipe_cmd.cpp
+++ b/src/zen/cmds/wipe_cmd.cpp
@@ -479,7 +479,7 @@ namespace {
{
if (!Quiet)
{
- ZEN_WARN("Failed removing directory {}. Reason: {}", DirectoryToDelete, Ex.what());
+ ZEN_CONSOLE_WARN("Failed removing directory {}. Reason: {}", DirectoryToDelete, Ex.what());
}
CleanWipe = false;
FailedDeleteCount++;
@@ -587,18 +587,7 @@ WipeCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
}
- try
- {
- CleanDirectory(m_Directory, {}, !m_KeepReadOnlyFiles, m_Dryrun);
- }
- catch (std::exception& Ex)
- {
- if (!m_Quiet)
- {
- ZEN_ERROR("{}", Ex.what());
- }
- return 3;
- }
+ CleanDirectory(m_Directory, {}, !m_KeepReadOnlyFiles, m_Dryrun);
return 0;
}
diff --git a/src/zen/cmds/workspaces_cmd.cpp b/src/zen/cmds/workspaces_cmd.cpp
index 773734f12..3930e56b7 100644
--- a/src/zen/cmds/workspaces_cmd.cpp
+++ b/src/zen/cmds/workspaces_cmd.cpp
@@ -185,7 +185,7 @@ WorkspaceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
HttpClient Http(m_HostName);
if (HttpClient::Response Result = Http.Get("/ws/refresh"); !Result)
{
- ZEN_CONSOLE("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
+ ZEN_CONSOLE_ERROR("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
}
}
ZEN_CONSOLE("Added/updated workspace {}", m_Id);
@@ -193,7 +193,7 @@ WorkspaceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_CONSOLE("Workspace {} already exists", m_Id);
+ ZEN_CONSOLE_WARN("Workspace {} already exists", m_Id);
return 0;
}
}
@@ -206,7 +206,7 @@ WorkspaceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
static std::vector<Workspaces::WorkspaceConfiguration> Configs = Workspaces::ReadConfig(Log(), StatePath, Error);
if (!Error.empty())
{
- ZEN_CONSOLE("Failed to read workspaces state from '{}'. Reason: '{}'", StatePath, Error);
+ ZEN_CONSOLE_ERROR("Failed to read workspaces state from '{}'. Reason: '{}'", StatePath, Error);
}
else
{
@@ -233,7 +233,7 @@ WorkspaceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
}
else
{
- ZEN_CONSOLE("Workspace {} not found", m_Id);
+ ZEN_CONSOLE_WARN("Workspace {} not found", m_Id);
}
}
}
@@ -257,14 +257,14 @@ WorkspaceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
HttpClient Http(m_HostName);
if (HttpClient::Response Result = Http.Get("/ws/refresh"); !Result)
{
- ZEN_CONSOLE("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
+ ZEN_CONSOLE_ERROR("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
}
}
ZEN_CONSOLE("Removed workspace {}", m_Id);
}
else
{
- ZEN_CONSOLE("Workspace {} does not exist", m_Id);
+ ZEN_CONSOLE_WARN("Workspace {} does not exist", m_Id);
}
return 0;
}
@@ -428,7 +428,7 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
Workspaces::WorkspaceConfiguration WorkspaceConfig = Workspaces::FindWorkspace(Log(), StatePath, WorkspaceId);
if (WorkspaceConfig.Id == Oid::Zero)
{
- ZEN_CONSOLE("Workspace {} does not exist", m_WorkspaceId);
+ ZEN_CONSOLE_ERROR("Workspace {} does not exist", m_WorkspaceId);
return 0;
}
m_WorkspaceRoot = WorkspaceConfig.RootPath;
@@ -481,7 +481,7 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
HttpClient Http(m_HostName);
if (HttpClient::Response Result = Http.Get("/ws/refresh"); !Result)
{
- ZEN_CONSOLE("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
+ ZEN_CONSOLE_ERROR("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
}
}
ZEN_CONSOLE("Created workspace share {}", m_ShareId);
@@ -602,7 +602,7 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
HttpClient Http(m_HostName);
if (HttpClient::Response Result = Http.Get("/ws/refresh"); !Result)
{
- ZEN_CONSOLE("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
+ ZEN_CONSOLE_ERROR("Failed to refresh workspaces for host {}. Reason: '{}'", m_HostName, Result.ErrorMessage(""sv));
}
}
ZEN_CONSOLE("Removed workspace share {}", m_ShareId);
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index accd0d105..240ba2a81 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -1030,10 +1030,35 @@ main(int argc, char** argv)
}
catch (const OptionParseException& Ex)
{
- std::string help = VerbOptions.help();
-
- printf("Error parsing arguments for command '%s': %s\n\n%s", SubCommand.c_str(), Ex.what(), help.c_str());
-
+ ZEN_CONSOLE_ERROR("Invalid arguments for command '{}': {}\n\n{}", SubCommand, Ex.what(), VerbOptions.help());
+ exit(11);
+ }
+ catch (const std::system_error& Ex)
+ {
+ if (IsOOD(Ex))
+ {
+ ZEN_CONSOLE_ERROR("Operation failed due to out of disk space: {}", Ex.what());
+ exit(3);
+ }
+ else if (IsOOM(Ex))
+ {
+ ZEN_CONSOLE_ERROR("Operation failed due to out of memory: {}", Ex.what());
+ exit(3);
+ }
+ else
+ {
+ ZEN_CONSOLE_ERROR("Operation failed due to system error: {} ({})\n", Ex.what(), Ex.code() ? Ex.code().value() : 0);
+ exit(Ex.code() ? Ex.code().value() : 10);
+ }
+ }
+ catch (const HttpClientError& Ex)
+ {
+ ZEN_CONSOLE_ERROR("Operation failed due to a http error: {}", Ex.what());
+ exit(Ex.m_Error != 0 ? Ex.m_Error : (int)Ex.m_ResponseCode);
+ }
+ catch (const std::exception& Ex)
+ {
+ ZEN_CONSOLE_ERROR("Operation failed due to: {}\n", Ex.what());
exit(11);
}
}
@@ -1051,14 +1076,30 @@ main(int argc, char** argv)
}
catch (const std::system_error& Ex)
{
- printf("System Error: %s\n", Ex.what());
-
- return Ex.code() ? Ex.code().value() : 10;
+ if (IsOOD(Ex))
+ {
+ printf("Operation failed due to out of disk space: %s", Ex.what());
+ return 3;
+ }
+ else if (IsOOM(Ex))
+ {
+ printf("Operation failed due to out of memory: %s", Ex.what());
+ return 3;
+ }
+ else
+ {
+ printf("Operation failed due to system error: %s (%d)\n", Ex.what(), Ex.code() ? Ex.code().value() : 0);
+ return Ex.code() ? Ex.code().value() : 10;
+ }
+ }
+ catch (const HttpClientError& Ex)
+ {
+ printf("Operation failed due to a http error: %s", Ex.what());
+ return Ex.m_Error != 0 ? Ex.m_Error : (int)Ex.m_ResponseCode;
}
catch (const std::exception& Ex)
{
- printf("Error: %s\n", Ex.what());
-
+ printf("Operation failed due to: %s\n", Ex.what());
return 11;
}
diff --git a/src/zencore/include/zencore/logging.h b/src/zencore/include/zencore/logging.h
index bffbe84b4..afbbbd3ee 100644
--- a/src/zencore/include/zencore/logging.h
+++ b/src/zencore/include/zencore/logging.h
@@ -59,7 +59,6 @@ struct LogCategory
zen::LoggerRef LoggerRef;
};
-void EmitConsoleLogMessage(int LogLevel, std::string_view Message);
void EmitConsoleLogMessage(int LogLevel, std::string_view Format, fmt::format_args Args);
void EmitLogMessage(LoggerRef& Logger, int LogLevel, std::string_view Message);
void EmitLogMessage(LoggerRef& Logger, const SourceLocation& Location, int LogLevel, std::string_view Message);
diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp
index 5885587ad..685c79d82 100644
--- a/src/zencore/logging.cpp
+++ b/src/zencore/logging.cpp
@@ -122,11 +122,34 @@ EmitConsoleLogMessage(int LogLevel, const std::string_view Message)
ConsoleLog().SpdLogger->log(InLevel, Message);
}
+#define ZEN_COLOR_YELLOW "\033[0;33m"
+#define ZEN_COLOR_RED "\033[0;31m"
+#define ZEN_BRIGHT_COLOR_RED "\033[1;31m"
+#define ZEN_COLOR_RESET "\033[0m"
+
void
EmitConsoleLogMessage(int LogLevel, std::string_view Format, fmt::format_args Args)
{
ZEN_MEMSCOPE(ELLMTag::Logging);
zen::logging::LoggingContext LogCtx;
+
+ // We are not using a format option for console which include log level since it would interfere with normal console output
+
+ const spdlog::level::level_enum InLevel = (spdlog::level::level_enum)LogLevel;
+ switch (InLevel)
+ {
+ case spdlog::level::level_enum::warn:
+ fmt::format_to(fmt::appender(LogCtx.MessageBuffer), ZEN_COLOR_YELLOW "Warning: " ZEN_COLOR_RESET);
+ break;
+ case spdlog::level::level_enum::err:
+ fmt::format_to(fmt::appender(LogCtx.MessageBuffer), ZEN_BRIGHT_COLOR_RED "Error: " ZEN_COLOR_RESET);
+ break;
+ case spdlog::level::level_enum::critical:
+ fmt::format_to(fmt::appender(LogCtx.MessageBuffer), ZEN_COLOR_RED "Critical: " ZEN_COLOR_RESET);
+ break;
+ default:
+ break;
+ }
fmt::vformat_to(fmt::appender(LogCtx.MessageBuffer), Format, Args);
zen::logging::EmitConsoleLogMessage(LogLevel, LogCtx.Message());
}
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp
index 4049ae815..392ca4aaa 100644
--- a/src/zenserver/config.cpp
+++ b/src/zenserver/config.cpp
@@ -1413,7 +1413,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
}
catch (const zen::OptionParseException& e)
{
- ZEN_CONSOLE_ERROR("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help());
+ ZEN_CONSOLE_ERROR("Invalid zenserver arguments: {}\n\n{}", e.what(), options.help());
throw;
}
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index d8922f885..f7d69617c 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -450,7 +450,7 @@ main(int argc, char* argv[])
{
if (IsDir(ServerOptions.DataDir))
{
- ZEN_CONSOLE_INFO("deleting files from '{}' ({})", ServerOptions.DataDir, DeleteReason);
+ ZEN_CONSOLE_INFO("Deleting files from '{}' ({})", ServerOptions.DataDir, DeleteReason);
DeleteDirectories(ServerOptions.DataDir);
}
}
@@ -463,7 +463,7 @@ main(int argc, char* argv[])
if (!ServerOptions.BaseSnapshotDir.empty())
{
- ZEN_CONSOLE_INFO("copying snapshot from '{}' into '{}", ServerOptions.BaseSnapshotDir, ServerOptions.DataDir);
+ ZEN_CONSOLE_INFO("Copying snapshot from '{}' into '{}", ServerOptions.BaseSnapshotDir, ServerOptions.DataDir);
CopyTree(ServerOptions.BaseSnapshotDir, ServerOptions.DataDir, {.EnableClone = true});
}