archive/tar: Header.FileInfo.Mode.IsRegular reports true for non-regular files #22903
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
Background
A tar file is a format for archiving a filesystem and is able to represent anything including regular files, directories, block and character devices, symlinks, and hardlinks.
Over the years, many incompatible extensions to tar have become common practice. Specifically, one them is the use of pseudo-files to encode additional information about a file or a set of files. A pseudo-file is encoded in the same way as a normal file, but the
Header.Typeflag
is set to some special value and the contents of the file are parsed according to some format determined by the typeflag. Both the GNU and PAX formats are heavy users of this approach.The Go implementation of tar provides automatic parsing of the metadata contained in these pseudo-files for the real file it describes. For example, Go1.1 added support for parsing long filenames for the GNU format; Go1.3 added support for parsing local PAX headers; and Go1.3 added support for parsing GNU sparse headers.
The problem
Parsing the metadata for a single file is easy to represent in the API since we can just represent the additional information in the Header struct.
However, the PAX format adds a feature called "global PAX headers" which encodes metadata intended to modify all subsequent files (#22748 indicates that this feature is actually used; e.g.,
git archive --format=tgz
produces them).In order to provide the metadata contained within a global PAX header,
Reader.Next
returns a singleHeader
representing the pseudo-file (in go1.10, we actually parse the PAX records intoHeader.PAXRecords
, but that is orthogonal to this issue).The problem with global headers (and really any typeflag that the Go implementation does not recognize) is that the following reports true:
This is the behavior on all versions of Go thus far.
The problem with
IsRegular
reporting true is:Header.FileInfo
alone is unable to handle pseudo-files specially (e.g., ignoring them).However, it is not trivial to have
Header.FileInfo.Mode.IsRegular
report false since the logic foros.FileMode.IsRegular
only reports false for a very narrow set of types, none of which are an obvious choice for "special" files like metadata or unrecognized typeflags.Thus, we need to make decision whether to keep or change the current behavior of
Header.FileInfo.Mode.IsRegular
for special files likeTypeXGlobalHeader
. If we change it, how do we make it report false? The only approach I see is to define a new constant (e.g.,ModeSpecial
) in theos
package.Thoughts?
\cc @rasky @bradfitz
The text was updated successfully, but these errors were encountered: