diff --git a/tar.go b/tar.go index ce719695..c07efb4f 100644 --- a/tar.go +++ b/tar.go @@ -17,6 +17,9 @@ func init() { } type Tar struct { + // If true, preserve only numeric user and group id + NumericUIDGID bool + // If true, errors encountered during reading or writing // a file within an archive will be logged and the // operation will continue on remaining files. @@ -71,7 +74,7 @@ func (t Tar) ArchiveAsync(ctx context.Context, output io.Writer, jobs <-chan Arc return nil } -func (Tar) writeFileToArchive(ctx context.Context, tw *tar.Writer, file File) error { +func (t Tar) writeFileToArchive(ctx context.Context, tw *tar.Writer, file File) error { if err := ctx.Err(); err != nil { return err // honor context cancellation } @@ -81,6 +84,10 @@ func (Tar) writeFileToArchive(ctx context.Context, tw *tar.Writer, file File) er return fmt.Errorf("file %s: creating header: %w", file.NameInArchive, err) } hdr.Name = file.NameInArchive // complete path, since FileInfoHeader() only has base name + if t.NumericUIDGID { + hdr.Uname = "" + hdr.Gname = "" + } if err := tw.WriteHeader(hdr); err != nil { return fmt.Errorf("file %s: writing header: %w", file.NameInArchive, err)