Skip to content

Commit 7643911

Browse files
committed
Ensure correct destination for multi_upload
1 parent 9e07a0b commit 7643911

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

tests/test_integrate.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,21 @@ auto start_seeder(const fs::path& data_dir,
196196
}
197197

198198
std::vector<std::string> args = {
199-
"docker",
200-
"run",
201-
"--rm",
202-
"--name",
203-
container_name,
204-
"--publish",
205-
fmt::format("{}:{}", port, port),
206-
"--volume",
199+
"docker", "run", "--rm", "--name", container_name,
200+
// Pass host UID/GID so container can fix file ownership on exit
201+
"--env", fmt::format("HOST_UID={}", getuid()), "--env",
202+
fmt::format("HOST_GID={}", getgid()), "--publish",
203+
fmt::format("{}:{}", port, port), "--volume",
207204
fmt::format("{}:{}", data_dir.generic_string(), container_data_dir),
208205
"--volume",
209206
fmt::format("{}:{}", torrent_file.parent_path().generic_string(),
210207
container_torrent_dir),
211208
// Needed to be able to run iptables in the container
212-
"--cap-add",
213-
"NET_ADMIN",
209+
"--cap-add", "NET_ADMIN",
214210
// For verbose output
215-
//"--env",
216-
// fmt::format("DEBUG={}",
217-
// logger()->should_log(spdlog::level::debug) ? "*" : "")
218-
};
211+
"--env",
212+
fmt::format("DEBUG={}",
213+
logger()->should_log(spdlog::level::debug) ? "*" : "")};
219214

220215
// Add host mapping so container can resolve host.docker.internal to host LAN
221216
// IP
@@ -245,7 +240,19 @@ auto start_seeder(const fs::path& data_dir,
245240
}
246241

247242
auto start_leecher(const fs::path& target, const fs::path& torrent_file) {
248-
fs::remove(target);
243+
try {
244+
if (fs::exists(target)) {
245+
// Ensure the directory is empty to avoid leftover files
246+
for (const auto& entry : fs::directory_iterator(target)) {
247+
fs::remove_all(entry);
248+
}
249+
}
250+
// Ensure the mount directory exists and is owned by the host user
251+
fs::create_directories(target);
252+
} catch (const std::exception& e) {
253+
logger()->warn("Failed preparing target directory {}: {}", target.string(),
254+
e.what());
255+
}
249256
return start_seeder(target, torrent_file, "leecher");
250257
}
251258

@@ -598,7 +605,8 @@ TEST_F(Integrate, DISABLED_upload) {
598605
const auto target = tmp_dir() / "upload_test";
599606
const auto destination = target / "1MiB.dat";
600607
// Be fully sure we do not have the file there yet
601-
ASSERT_FALSE(fs::exists(destination));
608+
ASSERT_FALSE(fs::exists(destination))
609+
<< "File already exists: " << destination;
602610

603611
std::optional<zit::Process> leecher;
604612
asio::steady_timer timer{m_io_context};
@@ -649,6 +657,10 @@ TEST_F(Integrate, DISABLED_multi_upload) {
649657

650658
// Start a leecher that we will upload to
651659
const auto target = tmp_dir() / "multi_upload_test";
660+
const auto destination = target / "multi"; // folder name inside torrent
661+
// Be fully sure we do not have the files there yet
662+
ASSERT_FALSE(fs::exists(destination))
663+
<< "File already exists: " << destination;
652664

653665
std::optional<zit::Process> leecher;
654666
asio::steady_timer timer{m_io_context};
@@ -672,5 +684,5 @@ TEST_F(Integrate, DISABLED_multi_upload) {
672684
torrent.run();
673685

674686
// Transfer done - Verify content
675-
verify_download(torrent, data_dir / torrent.name(), false);
687+
verify_download(torrent, destination, false);
676688
}

0 commit comments

Comments
 (0)