Filenames with backslashes causes a fatal error for Rex::Commands::Sync
还没有人认领这个 Issue。
评估
调研方向
从 Base.pm 第149行引用的 Rex::Interface::Fs::Base::_quotepath 开始,跟踪 sync_down 如何处理包含反斜杠的路径。使用提供的 Rexfile 在包含 systemd 文件名的主机上复现,然后验证 sync_down 完成时没有致命错误并保留该路径。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Rex terminates with errors (the error varies based on where it is thrown) if dealing with a filename containing backslashes.
Example:
[2023-09-20 11:16:14] INFO - Running task systemd on host
[2023-09-20 11:17:18] ERROR - Error executing task:
[2023-09-20 11:17:18] ERROR - Error running chmod 0755 /Users/mmusgrove/tmp/host/fs/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants at /Users/mmusgrove/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Rex/Interface/Fs/Base.pm line 149, <> line 145.
[2023-09-20 11:17:18] ERROR - 1 out of 1 task(s) failed:
[2023-09-20 11:17:18] ERROR - systemd failed on host
[2023-09-20 11:17:18] ERROR - Error running chmod 0755 /Users/mmusgrove/tmp/host/fs/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants at /Users/mmusgrove/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Rex/Interface/Fs/Base.pm line 149, <> line 145.
I was attempting to use rsync_down on /etc/systemd and it encountered this file:
[root@host ~]# ls -al /etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants/qemu-guest-agent.service
lrwxrwxrwx. 1 root root 48 Oct 20 2021 '/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants/qemu-guest-agent.service' -> /usr/lib/systemd/system/qemu-guest-agent.service
The host/fs/etc/systemd/ directory exists with ~/tmp.
The problem seems to be that Rex::Interface::Fs::Base::_quotepath is not handling backslashes. I can fix it if I override that method as follows:
{
# Allow /etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants to be synced
no warnings 'redefine';
*Rex::Interface::Fs::Base::_quotepath = sub {
my ( $self, $p ) = @_;
$p =~ s/([\\\@\$\% ])/\\$1/g; # Note the extra \\ before \@
return $p;
};
}
Expected behavior
I would expect the sync_down to function the same regardless of whether or not the filename contains a backslash character.
How to reproduce it
Modify the following Rexfile to use a valid hostname of a Linux system with qemu installed you can connect to with ssh
mkdir -p ~/tmp/host/fs/etc/systemd # where host is the same hostname
Place the Rexfile into ~/tmp.
cd ~/tmp
rex systemd
Code example
# Rexfile
use Rex -feature => ['1.4'];
group myservers => 'host';
desc 'Get /etc/systemd';
task 'systemd',
group => 'myservers',
sub {
my $server = connection->server;
sync_down "/etc/systemd", "$server/fs/etc/systemd/";
};
Additional context
No response
Rex version
(R)?ex 1.14.3
Perl version
v5.26.3
Operating system running rex
Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020 arm64
Operating system managed by rex
AlmaLinux 8.8 (Sapphire Caracal)
How rex was installed?
package manager
- 主要语言
- Perl
- 星标
- 737
- 派生
- 214
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RexOps/Rex 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 3/5 1-2 天 新手友好度 45/100
-
triage needed
难度 4/5 3-5 天 新手友好度 35/100
-
bug
难度 3/5 1-2 天 新手友好度 35/100
-
triage needed
难度 3/5 1-2 天 新手友好度 42/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 87/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
fglock/PerlOnJava#1579 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
objectionary/eolang.sty#184 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 82/100
linux-test-project/lcov#542 ·