2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright (C) 2017-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2021-08-16 01:45:50 +00:00
|
|
|
|
2024-02-25 22:12:08 +00:00
|
|
|
#include <libtransmission/file.h> // tr_sys_dir_get_current()
|
2023-10-30 17:44:34 +00:00
|
|
|
#include <libtransmission/utils.h> // tr_env_get_string()
|
2021-08-16 01:45:50 +00:00
|
|
|
|
2024-02-25 22:12:08 +00:00
|
|
|
#include <fmt/core.h>
|
2024-03-25 14:13:09 +00:00
|
|
|
#include <fmt/ostream.h>
|
2024-02-25 22:12:08 +00:00
|
|
|
|
2024-03-25 14:13:09 +00:00
|
|
|
#include <fstream>
|
2021-08-16 01:45:50 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc < 3)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto const result_path = std::string{ argv[1] };
|
|
|
|
auto const test_action = std::string{ argv[2] };
|
|
|
|
auto const tmp_result_path = result_path + ".tmp";
|
|
|
|
|
2024-03-25 14:13:09 +00:00
|
|
|
auto out = std::ofstream(tmp_result_path.c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
|
|
|
|
if (!out)
|
2021-08-16 01:45:50 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_action == "--dump-args")
|
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
for (int i = 3; i < argc; ++i)
|
2021-08-16 01:45:50 +00:00
|
|
|
{
|
2024-02-25 22:12:08 +00:00
|
|
|
fmt::print(out, "{:s}\n", argv[i]);
|
2021-08-16 01:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (test_action == "--dump-env")
|
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
for (int i = 3; i < argc; ++i)
|
2021-08-16 01:45:50 +00:00
|
|
|
{
|
2024-02-25 22:12:08 +00:00
|
|
|
fmt::print(out, "{:s}\n", tr_env_get_string(argv[i], "<null>"));
|
2021-08-16 01:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (test_action == "--dump-cwd")
|
|
|
|
{
|
2024-02-25 22:12:08 +00:00
|
|
|
auto cwd = tr_sys_dir_get_current(nullptr);
|
|
|
|
|
|
|
|
if (std::empty(cwd))
|
|
|
|
{
|
|
|
|
cwd = "<null>";
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt::print(out, "{:s}\n", cwd);
|
2021-08-16 01:45:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-25 14:13:09 +00:00
|
|
|
out.close();
|
2024-03-04 05:29:38 +00:00
|
|
|
(void)std::remove(tmp_result_path.c_str());
|
2021-08-16 01:45:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:13:09 +00:00
|
|
|
out.close();
|
2024-02-25 22:12:08 +00:00
|
|
|
tr_sys_path_rename(tmp_result_path.c_str(), result_path.c_str());
|
2021-08-16 01:45:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|