Ste*_*ieD 7 locale libarchive raku
tar.gz我正在使用Libarchive::Read模块获取文件的文件列表。当 tarball 文件名中包含 UTF-8 字符时,我收到由 libarchive C 库生成的错误:
Pathname can't be converted from UTF-8 to current locale.
in block at /Users/steve/.rakubrew/versions/moar-2022.12/share/perl6/site/sources/42AF7739DF41B2DA0C4BF2069157E2EF165CE93E (Libarchive::Read) line 228
这里的 Raku 代码引发错误:
my $r := Libarchive::Read.new($newest_file);
my $needs_update = False;
for $r -> $entry { # WARNING THROWN HERE for each file in tarball listing
$entry.pathname;
$needs_update = True if $entry.is-file && $entry.pathname && $entry.pathname ~~ / ( \.t || \.pm || \.pm6 ) $ / ;
last if $needs_update;
}
Run Code Online (Sandbox Code Playgroud)
我在Mac上。该locale命令报告以下内容:
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)
libarchive C 库似乎有一个已充分报告的错误:https://github.com/libarchive/libarchive/issues/587。
无论如何,有没有办法告诉 Raku 告诉模块正在使用什么区域设置,以便我可以获得带有 utf-8 字符的 tarball 列表?
为了解决这个问题,我转向了更新的 Raku 模块Archive::Libarchive。这段代码可以毫无抱怨地工作:
my Archive::Libarchive $a .= new: operation => LibarchiveRead, file => $newest_file.Str;
my Archive::Libarchive::Entry $entry .= new;
my $needs_update = False;
while $a.next-header($entry) {
$a.data-skip;
$needs_update = True if $entry.pathname.substr(*-1) ne '/' && $entry.pathname && $entry.pathname ~~ / ( \.t || \.pm || \.pm6 ) $ / ;
last if $needs_update;
}
$a.close;
Run Code Online (Sandbox Code Playgroud)
该代码还使用了 libarchive C 库,但我猜想以一种知道如何使用 utf-8 字符的方式。
| 归档时间: |
|
| 查看次数: |
1012 次 |
| 最近记录: |