navid/veins / commit
071d914946b6
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: 625628f882b9
Browse files at this commit · Download source
--- a/xveins/src/cli/net_commands.cpp+++ b/xveins/src/cli/net_commands.cpp@@ -593,7 +593,20 @@ } if (path.empty()) path = last_segment(parsed->path);- auto repo = init_repo(path_from_bytes(path));+ const fs::path destination = path_from_bytes(path);+ if (path_exists(destination)) {+ if (!path_is_dir(destination)) {+ error_prefix();+ std::cout << "destination already exists and is not a directory: " << path << "\n";+ return 1;+ }+ if (!list_directory(destination).empty()) {+ error_prefix();+ std::cout << "destination directory is not empty: " << path << "\n";+ return 1;+ }+ }+ auto repo = init_repo(destination); if (!repo) { error_prefix(); std::cout << "cannot create repository\n";--- a/xveins/tests/integration_tests.cpp+++ b/xveins/tests/integration_tests.cpp@@ -1210,6 +1210,7 @@ make_source_repository(f); const fs::path source = f.root / "source"; const fs::path clone = f.root / "clone";+ fs::create_directories(clone); f.vn({"clone", "file://" + source.string(), clone.string()}, f.root); t.expect_eq(f.read("a.txt", clone), "hello\n"); t.expect_contains(f.vn({"log"}, clone).out, "initial");@@ -1268,6 +1269,16 @@ f.init(); f.failed({"clone", "not-a-url", "dest"}, "unsupported URL"); f.failed({"clone", "file:///does/not/exist", "dest"}, "error:");++ const fs::path occupied = f.root / "occupied";+ fs::create_directories(occupied);+ if (!write_file(occupied / "keep.txt", bytes_of("keep\n")))+ throw test::Failure("cannot write occupied directory file");+ const std::string source = "file://" + f.repo.string();+ f.failed({"clone", source, occupied.string()}, "destination directory is not empty", f.root);+ f.failed({"gg", source, occupied.string()}, "destination directory is not empty", f.root);+ f.failed({"clone", source, (occupied / "keep.txt").string()},+ "destination already exists and is not a directory", f.root); } void errors_bad_arguments(test::Context& t) {