Skip to content

Commit 5665b87

Browse files
bors[bot]andrei-toterman
authored andcommitted
Merge #2893
2893: [cli/transfer] don't treat windows absolute paths as instance:path pair r=ricab a=andrei-toterman fix #2891 Co-authored-by: Andrei Toterman <[email protected]>
1 parent e359350 commit 5665b87

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/client/cli/cmd/transfer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <fmt/std.h>
2727

28+
#include <QRegularExpression>
29+
2830
namespace mp = multipass;
2931
namespace cmd = multipass::cmd;
3032
namespace mcp = multipass::cli::platform;
@@ -163,9 +165,16 @@ std::vector<std::pair<std::string, fs::path>> cmd::Transfer::args_to_instance_an
163165
instance_entry_args.reserve(args.size());
164166
for (const auto& entry : args)
165167
{
168+
// this is needed so that Windows absolute paths are not split at the colon following the drive letter
169+
if (QRegularExpression{R"(^[A-Za-z]:\\.*)"}.match(entry).hasMatch())
170+
{
171+
instance_entry_args.emplace_back("", entry.toStdString());
172+
continue;
173+
}
174+
166175
const auto source_components = entry.split(':');
167176
const auto instance_name = source_components.size() == 1 ? "" : source_components.first().toStdString();
168-
const auto file_path = source_components.size() == 1 ? source_components.first() : source_components.at(1);
177+
const auto file_path = source_components.size() == 1 ? source_components.first() : entry.section(':', 1);
169178
if (!instance_name.empty())
170179
request.add_instance_name()->append(instance_name);
171180
instance_entry_args.emplace_back(instance_name, file_path.isEmpty() ? "." : file_path.toStdString());

tests/test_cli_client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ TEST_F(Client, transfer_cmd_local_source_instance_target)
603603
auto mocked_sftp_client_p = mocked_sftp_client.get();
604604

605605
EXPECT_CALL(*mocked_sftp_utils, make_SFTPClient).WillOnce(Return(std::move(mocked_sftp_client)));
606-
EXPECT_CALL(*mocked_sftp_client_p, push).WillOnce(Return(true));
606+
EXPECT_CALL(*mocked_sftp_client_p, push).WillRepeatedly(Return(true));
607+
EXPECT_CALL(*mocked_sftp_client_p, is_remote_dir).WillOnce(Return(true));
607608
EXPECT_CALL(mock_daemon, ssh_info)
608609
.WillOnce([](auto, grpc::ServerReaderWriter<mp::SSHInfoReply, mp::SSHInfoRequest>* server) {
609610
mp::SSHInfoReply reply;
@@ -612,7 +613,7 @@ TEST_F(Client, transfer_cmd_local_source_instance_target)
612613
return grpc::Status{};
613614
});
614615

615-
EXPECT_EQ(send_command({"transfer", "foo", "test-vm:bar"}), mp::ReturnCode::Ok);
616+
EXPECT_EQ(send_command({"transfer", "foo", "C:\\Users\\file", "test-vm:bar"}), mp::ReturnCode::Ok);
616617
}
617618

618619
TEST_F(Client, transfer_cmd_help_ok)

0 commit comments

Comments
 (0)