try {
if (is_ccache_executable(argv[0])) {
if (argc < 2) {
- PRINT_RAW(
+ PRINT(
stderr,
+ "{}",
core::get_usage_text(util::pstr(fs::path(argv[0]).filename()).str()));
exit(EXIT_FAILURE);
}
*incompressible_data_unit,
});
- PRINT_RAW(stdout, table.render());
+ PRINT(stdout, "{}", table.render());
}
static void
const auto [counters, last_updated] =
storage::local::LocalStorage(config).get_all_statistics();
Statistics statistics(counters);
- PRINT_RAW(
- stdout,
- statistics.format_machine_readable(config, last_updated, format));
+ PRINT(stdout,
+ "{}",
+ statistics.format_machine_readable(config, last_updated, format));
break;
}
storage::local::LocalStorage(config).clean_all(
[&](double progress) { progress_bar.update(progress); });
if (isatty(STDOUT_FILENO)) {
- PRINT_RAW(stdout, "\n");
+ PRINT(stdout, "\n");
}
break;
}
storage::local::LocalStorage(config).wipe_all(
[&](double progress) { progress_bar.update(progress); });
if (isatty(STDOUT_FILENO)) {
- PRINT_RAW(stdout, "\n");
+ PRINT(stdout, "\n");
}
break;
}
config.set_value_in_file(
util::pstr(config.config_path()), "max_files", arg);
if (files == 0) {
- PRINT_RAW(stdout, "Unset cache file limit\n");
+ PRINT(stdout, "Unset cache file limit\n");
} else {
PRINT(stdout, "Set cache file limit to {}\n", files);
}
config.set_value_in_file(
util::pstr(config.config_path()), "max_size", arg);
if (max_size == 0) {
- PRINT_RAW(stdout, "Unset cache size limit\n");
+ PRINT(stdout, "Unset cache size limit\n");
} else {
PRINT(stdout,
"Set cache size limit to {}\n",
Statistics statistics(StatsLog(config.stats_log()).read());
const auto timestamp =
DirEntry(config.stats_log(), DirEntry::LogOnError::yes).mtime();
- PRINT_RAW(
+ PRINT(
stdout,
+ "{}",
statistics.format_human_readable(config, timestamp, verbosity, true));
break;
}
Statistics statistics(StatsLog(config.stats_log()).read());
const auto timestamp =
DirEntry(config.stats_log(), DirEntry::LogOnError::yes).mtime();
- PRINT_RAW(stdout,
- statistics.format_machine_readable(config, timestamp, format));
+ PRINT(stdout,
+ "{}",
+ statistics.format_machine_readable(config, timestamp, format));
break;
}
const auto [counters, last_updated] =
storage::local::LocalStorage(config).get_all_statistics();
Statistics statistics(counters);
- PRINT_RAW(stdout,
- statistics.format_human_readable(
- config, last_updated, verbosity, false));
+ PRINT(stdout,
+ "{}",
+ statistics.format_human_readable(
+ config, last_updated, verbosity, false));
break;
}
case 'V': // --version
{
- PRINT_RAW(stdout,
- get_version_text(util::pstr(fs::path(argv[0]).stem()).str()));
+ PRINT(stdout,
+ "{}",
+ get_version_text(util::pstr(fs::path(argv[0]).stem()).str()));
break;
}
storage::local::LocalStorage(config).get_compression_statistics(
threads, [&](double progress) { progress_bar.update(progress); });
if (isatty(STDOUT_FILENO)) {
- PRINT_RAW(stdout, "\n\n");
+ PRINT(stdout, "\n\n");
}
print_compression_statistics(config, compression_statistics);
break;
case 'z': // --zero-stats
storage::local::LocalStorage(config).zero_all_statistics();
- PRINT_RAW(stdout, "Statistics zeroed\n");
+ PRINT(stdout, "Statistics zeroed\n");
break;
default:
evict_max_age,
evict_namespace);
if (isatty(STDOUT_FILENO)) {
- PRINT_RAW(stdout, "\n");
+ PRINT(stdout, "\n");
}
}
stream, " Hash: {}\n", util::format_base16(m_file_infos[i].digest));
PRINT(stream, " File size: {}\n", m_file_infos[i].fsize);
if (m_file_infos[i].mtime == util::TimePoint()) {
- PRINT_RAW(stream, " Mtime: -\n");
+ PRINT(stream, " Mtime: -\n");
} else {
PRINT(stream,
" Mtime: {}.{:09}\n",
util::nsec_part(m_file_infos[i].mtime));
}
if (m_file_infos[i].ctime == util::TimePoint()) {
- PRINT_RAW(stream, " Ctime: -\n");
+ PRINT(stream, " Ctime: -\n");
} else {
PRINT(stream,
" Ctime: {}.{:09}\n",
PRINT(stream, "Results ({}):\n", m_results.size());
for (size_t i = 0; i < m_results.size(); ++i) {
PRINT(stream, " {}:\n", i);
- PRINT_RAW(stream, " File info indexes:");
+ PRINT(stream, " File info indexes:");
for (uint32_t file_info_index : m_results[i].file_info_indexes) {
PRINT(stream, " {}", file_info_index);
}
- PRINT_RAW(stream, "\n");
+ PRINT(stream, "\n");
PRINT(stream, " Key: {}\n", util::format_base16(m_results[i].key));
}
}
thread_pool.shut_down();
if (isatty(STDOUT_FILENO)) {
- PRINT_RAW(stdout, "\n\n");
+ PRINT(stdout, "\n\n");
}
const double old_ratio =
*size_diff_unit,
});
- PRINT_RAW(stdout, table.render());
+ PRINT(stdout, "{}", table.render());
}
// Private methods
main(int argc, char** argv)
{
if (argc != 5) {
- PRINT_RAW(stderr,
- "Usage: test-lockfile PATH SECONDS <short|long>"
- " <blocking|non-blocking>\n");
+ PRINT(stderr,
+ "Usage: test-lockfile PATH SECONDS <short|long>"
+ " <blocking|non-blocking>\n");
return 1;
}
Config config;
const bool long_lived = std::string(argv[3]) == "long";
const bool blocking = std::string(argv[4]) == "blocking";
if (!seconds) {
- PRINT_RAW(stderr, "Error: Failed to parse seconds\n");
+ PRINT(stderr, "Error: Failed to parse seconds\n");
return 1;
}
util::LockFile lock(path);
bool acquired = false;
if (blocking) {
- PRINT_RAW(stdout, "Acquiring\n");
+ PRINT(stdout, "Acquiring\n");
acquired = lock.acquire();
} else {
- PRINT_RAW(stdout, "Trying to acquire\n");
+ PRINT(stdout, "Trying to acquire\n");
acquired = lock.try_acquire();
}
return 1;
}
- PRINT_RAW(stdout, "Acquired\n");
+ PRINT(stdout, "Acquired\n");
if (long_lived) {
lock.make_long_lived(lock_manager);
}
PRINT(stdout, "Sleeping {} second{}\n", *seconds, *seconds == 1 ? "" : "s");
std::this_thread::sleep_for(std::chrono::seconds{*seconds});
- PRINT_RAW(stdout, "Releasing\n");
+ PRINT(stdout, "Releasing\n");
lock.release();
- PRINT_RAW(stdout, "Released\n");
+ PRINT(stdout, "Released\n");
}
#define FMT(format_, ...) fmt::format(format_, __VA_ARGS__)
// Convenience macro for `fmt::print`.
-#define PRINT(stream_, format_, ...) fmt::print(stream_, format_, __VA_ARGS__)
-
-// Convenience macro for calling `fmt::print` with a message that is not a
-// format string.
-#define PRINT_RAW(stream_, message_) fmt::print(stream_, "{}", message_)
+#define PRINT(stream_, format_, ...) \
+ fmt::print(stream_, format_ __VA_OPT__(, ) __VA_ARGS__)
template<>
struct fmt::formatter<std::filesystem::path> : fmt::formatter<std::string_view>
cmd_get(storage::remote::Client& client, const std::vector<std::string>& args)
{
if (args.size() != 3 || args[1] != "-o") {
- PRINT_RAW(stderr, "Error: get requires: KEY -o OUTPUT\n");
- PRINT_RAW(stderr, " where OUTPUT is a file path or - for stdout\n");
+ PRINT(stderr, "Error: get requires: KEY -o OUTPUT\n");
+ PRINT(stderr, " where OUTPUT is a file path or - for stdout\n");
return 1;
}
}
if (args.size() - start_idx != 3) {
- PRINT_RAW(stderr,
- "Error: put requires: [--overwrite] KEY -i INPUT\n"
- " or: [--overwrite] KEY -v VALUE\n"
- " where INPUT is a file path or - for stdin\n");
+ PRINT(stderr,
+ "Error: put requires: [--overwrite] KEY -i INPUT\n"
+ " or: [--overwrite] KEY -v VALUE\n"
+ " where INPUT is a file path or - for stdin\n");
return 1;
}
const std::vector<std::string>& args)
{
if (args.size() != 1) {
- PRINT_RAW(stderr, "Error: remove requires exactly 1 argument: KEY\n");
+ PRINT(stderr, "Error: remove requires exactly 1 argument: KEY\n");
return 1;
}
cmd_stop(storage::remote::Client& client, const std::vector<std::string>& args)
{
if (!args.empty()) {
- PRINT_RAW(stderr, "Error: stop takes no arguments\n");
+ PRINT(stderr, "Error: stop takes no arguments\n");
return 1;
}
return 1;
}
- PRINT_RAW(stdout, "Helper stopped\n");
+ PRINT(stdout, "Helper stopped\n");
return 0;
}
cmd_ping(storage::remote::Client& client, const std::vector<std::string>& args)
{
if (!args.empty()) {
- PRINT_RAW(stderr, "Error: ping takes no arguments\n");
+ PRINT(stderr, "Error: ping takes no arguments\n");
return 1;
}
// Connection and protocol verification already done in main.
- PRINT_RAW(stdout, "Helper is reachable\n");
+ PRINT(stdout, "Helper is reachable\n");
return 0;
}
if (!client.has_capability(
storage::remote::Client::Capability::get_put_remove_stop)) {
- PRINT_RAW(stderr,
- "Helper does not support get/put/remove/stop operations\n");
+ PRINT(stderr, "Helper does not support get/put/remove/stop operations\n");
return 1;
}