1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00
transmission/tests/libtransmission/subprocess-test-program.cc
Mike Gelfand 1c421d6d23
Minor CMake maintainability improvements (#6186)
* Prefer `PROJECT_{SOURCE,BINARY}_DIR` to `CMAKE_` ones

* Extend use of 3rd-party dir vars to reduce duplication

* Fix typo in submodule repo name

* Remove `CURL::libcurl` target fallback

The target is always available since CMake 3.12, which is our current
minimum version.
2023-10-30 20:44:34 +03:00

63 lines
1.7 KiB
C++

// This file Copyright (C) 2017-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <libtransmission/file.h> // tr_sys_file_write_line(), tr_sys_file_close(), tr_sy...
#include <libtransmission/utils.h> // tr_env_get_string()
#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")
{
for (int i = 3; i < argc; ++i)
{
tr_sys_file_write_line(fd, argv[i]);
}
}
else if (test_action == "--dump-env")
{
for (int i = 3; i < argc; ++i)
{
auto const value = tr_env_get_string(argv[i], "<null>");
tr_sys_file_write_line(fd, value);
}
}
else if (test_action == "--dump-cwd")
{
auto const value = tr_sys_dir_get_current(nullptr);
tr_sys_file_write_line(fd, !std::empty(value) ? value : "<null>");
}
else
{
tr_sys_file_close(fd);
tr_sys_path_remove(tmp_result_path.data());
return 1;
}
tr_sys_file_close(fd);
tr_sys_path_rename(tmp_result_path.data(), result_path.data());
return 0;
}