Trying to pipe GNU Tar output to another process fails. I do this to write the output to another machine via ssh. I have distilled it down to the simple case: gtar -c somefile.txt | cat > somefile.tar I receive the following error: gtar: /dev/sa0: Cannot open: Operation not supported gtar: Error is not recoverable: exiting now I have tried this on fedora, ubuntu, and netbsd, and all create the file somefile.tar as expected. bsd tar works fine: tar -c somefile.txt | cat > somefile.tar Creates the file as expected. Unfortunately I need gnu tar due to the incremental options not available in bsd tar. I'm running 13.2 release. gnu tar is latest version 1.34 installed from pkg.
If you want tar(1) to read from/write to stdout, you need to specify this with "-f -". gtar -cf - somefile.txt | cat >somefile.tar Historically, tar(1) has defaulted to accessing a tape device if no archive file was specified. I configured gtar to match the base system tar in this regard. As of libarchive 3.6.0 from a year ago, bsdtar (the FreeBSD base system tar) implements a new behavior: It checks if /dev/sa0 exists. If yes, it will use that device as default archive. If not, it will use stdin/stdout. Confusing? You still need to specify the archive with -f to avoid surprises. Anyway, I'll change gtar to default to stdin/stdout, since that seems to be the direction where things are heading.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=5ea94b852ffe7d9f95c3012f239435556c8a44d5 commit 5ea94b852ffe7d9f95c3012f239435556c8a44d5 Author: Christian Weisgerber <naddy@FreeBSD.org> AuthorDate: 2023-05-05 21:46:49 +0000 Commit: Christian Weisgerber <naddy@FreeBSD.org> CommitDate: 2023-05-05 22:01:18 +0000 archivers/gtar: switch the default archive to stdin/stdout The gtar port tries to use the same default archive location as the base system tar. Starting with libarchive 3.6.0, bsdtar defaults to reading/writing the archive from stdin/to stdout in the common case where the /dev/sa0 device does not exist on a system. Using "-" as the default archive file is also the GNU upstream default. PR: 271260 Reported by: Michael Stone <mstone2001@msn.com> archivers/gtar/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
I committed the change, thanks.
*** Bug 271261 has been marked as a duplicate of this bug. ***
Thank you so much for the quick response and for making this change, I do believe this change is the correct behavior, as it is consistent with other platforms. I appreciate the fast resolution, and can verify my issue is resolved. Thanks again.