diff --git a/src/client/cli/cmd/transfer.cpp b/src/client/cli/cmd/transfer.cpp index 85e57ecb95..53e09aaa08 100644 --- a/src/client/cli/cmd/transfer.cpp +++ b/src/client/cli/cmd/transfer.cpp @@ -25,6 +25,8 @@ #include +#include + namespace mp = multipass; namespace cmd = multipass::cmd; namespace mcp = multipass::cli::platform; @@ -163,9 +165,16 @@ std::vector> cmd::Transfer::args_to_instance_an instance_entry_args.reserve(args.size()); for (const auto& entry : args) { + // this is needed so that Windows absolute paths are not split at the colon following the drive letter + if (QRegularExpression{R"(^[A-Za-z]:\\.*)"}.match(entry).hasMatch()) + { + instance_entry_args.emplace_back("", entry.toStdString()); + continue; + } + const auto source_components = entry.split(':'); const auto instance_name = source_components.size() == 1 ? "" : source_components.first().toStdString(); - const auto file_path = source_components.size() == 1 ? source_components.first() : source_components.at(1); + const auto file_path = source_components.size() == 1 ? source_components.first() : entry.section(':', 1); if (!instance_name.empty()) request.add_instance_name()->append(instance_name); instance_entry_args.emplace_back(instance_name, file_path.isEmpty() ? "." : file_path.toStdString()); diff --git a/tests/test_cli_client.cpp b/tests/test_cli_client.cpp index a6f902ba9d..6cc601ff24 100644 --- a/tests/test_cli_client.cpp +++ b/tests/test_cli_client.cpp @@ -603,7 +603,8 @@ TEST_F(Client, transfer_cmd_local_source_instance_target) auto mocked_sftp_client_p = mocked_sftp_client.get(); EXPECT_CALL(*mocked_sftp_utils, make_SFTPClient).WillOnce(Return(std::move(mocked_sftp_client))); - EXPECT_CALL(*mocked_sftp_client_p, push).WillOnce(Return(true)); + EXPECT_CALL(*mocked_sftp_client_p, push).WillRepeatedly(Return(true)); + EXPECT_CALL(*mocked_sftp_client_p, is_remote_dir).WillOnce(Return(true)); EXPECT_CALL(mock_daemon, ssh_info) .WillOnce([](auto, grpc::ServerReaderWriter* server) { mp::SSHInfoReply reply; @@ -612,7 +613,7 @@ TEST_F(Client, transfer_cmd_local_source_instance_target) return grpc::Status{}; }); - EXPECT_EQ(send_command({"transfer", "foo", "test-vm:bar"}), mp::ReturnCode::Ok); + EXPECT_EQ(send_command({"transfer", "foo", "C:\\Users\\file", "test-vm:bar"}), mp::ReturnCode::Ok); } TEST_F(Client, transfer_cmd_help_ok)