Skip to content

Commit

Permalink
Merge #2893
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
2 people authored and Chris Townsend committed Jan 27, 2023
1 parent e359350 commit 5665b87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/client/cli/cmd/transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <fmt/std.h>

#include <QRegularExpression>

namespace mp = multipass;
namespace cmd = multipass::cmd;
namespace mcp = multipass::cli::platform;
Expand Down Expand Up @@ -163,9 +165,16 @@ std::vector<std::pair<std::string, fs::path>> 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());
Expand Down
5 changes: 3 additions & 2 deletions tests/test_cli_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mp::SSHInfoReply, mp::SSHInfoRequest>* server) {
mp::SSHInfoReply reply;
Expand All @@ -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)
Expand Down

0 comments on commit 5665b87

Please sign in to comment.