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
|
|
|
|
2023-10-30 17:44:34 +00:00
|
|
|
#include <libtransmission/file.h> // tr_sys_file_write_line(), tr_sys_file_close(), tr_sy...
|
|
|
|
#include <libtransmission/utils.h> // tr_env_get_string()
|
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";
|
|
|
|
|
|
|
|
auto fd = tr_sys_file_open(
|
|
|
|
tmp_result_path.data(), // NOLINT
|
|
|
|
TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE,
|
|
|
|
0644,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
if (fd == TR_BAD_SYS_FILE)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2022-03-27 17:37:29 +00:00
|
|
|
tr_sys_file_write_line(fd, 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
|
|
|
{
|
2022-07-27 04:26:37 +00:00
|
|
|
auto const value = tr_env_get_string(argv[i], "<null>");
|
2022-03-27 17:37:29 +00:00
|
|
|
tr_sys_file_write_line(fd, value);
|
2021-08-16 01:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (test_action == "--dump-cwd")
|
|
|
|
{
|
2022-08-04 04:59:41 +00:00
|
|
|
auto const value = tr_sys_dir_get_current(nullptr);
|
|
|
|
tr_sys_file_write_line(fd, !std::empty(value) ? value : "<null>");
|
2021-08-16 01:45:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-27 17:37:29 +00:00
|
|
|
tr_sys_file_close(fd);
|
|
|
|
tr_sys_path_remove(tmp_result_path.data());
|
2021-08-16 01:45:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-03-27 17:37:29 +00:00
|
|
|
tr_sys_file_close(fd);
|
|
|
|
tr_sys_path_rename(tmp_result_path.data(), result_path.data());
|
2021-08-16 01:45:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|