Bug 271260 - archivers/gtar: GNU tar fails to write to pipe via stdout.
Summary: archivers/gtar: GNU tar fails to write to pipe via stdout.
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Christian Weisgerber
URL:
Keywords:
: 271261 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-05-05 14:33 UTC by Michael Stone
Modified: 2023-05-09 19:48 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (naddy)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Stone 2023-05-05 14:33:06 UTC
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.
Comment 1 Christian Weisgerber freebsd_committer freebsd_triage 2023-05-05 21:41:06 UTC
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.
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-05-05 22:02:16 UTC
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(-)
Comment 3 Christian Weisgerber freebsd_committer freebsd_triage 2023-05-05 22:05:26 UTC
I committed the change, thanks.
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2023-05-06 00:27:32 UTC
*** Bug 271261 has been marked as a duplicate of this bug. ***
Comment 5 Michael Stone 2023-05-09 19:48:07 UTC
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.