cmake -E tar xfz fails for 7zip files if locale is not set
I stumbled upon this problem when I was trying to use cmake -E tar
with the boost 7zip file. The error only happens when the locale of the system is not properly set, this is for example the case inside the ubuntu docker container. The strange effect is that the cmake -E tar
command works on a usual linux workstation, but not inside the docker container, which is quite cumbersome.
It seems to be a "problem" of libarchive but it should be possible to circumvent it: https://github.com/libarchive/libarchive/issues/587
How to reproduce
docker run --rm -it ubuntu:22.04 bash
cd opt/
# install version 3.27.4 of cmake (it also happens with the system provided cmake)
mkdir cmake
apt update && apt install -y wget
wget --no-check-certificate --quiet -O - https://github.com/Kitware/CMake/releases/download/v3.27.4/cmake-3.27.4-linux-x86_64.tar.gz | tar --strip-components=1 -xz -C cmake
# Get boost 7zip file and try to extract it:
wget https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.7z
/opt/cmake/bin/cmake -E tar xfz boost_1_80_0.7z
Error message:
CMake Error: Problem with archive_read_next_header(): Pathname cannot be converted from UTF-16LE to current locale.
CMake Error: Problem extracting tar: boost_1_80_0.7z
Possible workaround
Set the environment variable LANG=C.UTF-8