Skip to content

Roll tar to 0.5.5+1 #3447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/third_party/tar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Vendored elements from `package:tar` for use in creation and extraction of
tar-archives.

* Repository: `https://github.com/simolus3/tar/`
* Revision: `7cdb563c9894600c6a739ec268f8673d6122006f`
* Revision: `901ae404e0a225d9b08e5253415ca092f5c08706`
3 changes: 3 additions & 0 deletions lib/src/third_party/tar/src/charcodes.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@internal
import 'package:meta/meta.dart';

/// "Line feed" control character.
const int $lf = 0x0a;

Expand Down
73 changes: 4 additions & 69 deletions lib/src/third_party/tar/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@internal
import 'dart:typed_data';

import 'package:meta/meta.dart';

import 'charcodes.dart';
import 'exception.dart';
import 'header.dart' show TarHeader; // for dartdoc
import 'header.dart';

// Magic values to help us identify the TAR header type.
const magicGnu = [$u, $s, $t, $a, $r, $space]; // 'ustar '
Expand All @@ -11,74 +14,6 @@ const magicUstar = [$u, $s, $t, $a, $r, 0]; // 'ustar\x00'
const versionUstar = [$0, $0]; // '00'
const trailerStar = [$t, $a, $r, 0]; // 'tar\x00'

/// Type flags for [TarHeader].
///
/// The type flag of a header indicates the kind of file associated with the
/// entry. This enum contains the various type flags over the different TAR
/// formats, and users should be careful that the type flag corresponds to the
/// TAR format they are working with.
enum TypeFlag {
/// [reg] indicates regular files.
///
/// Old tar implementations have a seperate `TypeRegA` value. This library
/// will transparently read those as [regA].
reg,

/// Legacy-version of [reg] in old tar implementations.
///
/// This is only used internally.
regA,

/// Hard link - header-only, may not have a data body
link,

/// Symbolic link - header-only, may not have a data body
symlink,

/// Character device node - header-only, may not have a data body
char,

/// Block device node - header-only, may not have a data body
block,

/// Directory - header-only, may not have a data body
dir,

/// FIFO node - header-only, may not have a data body
fifo,

/// Currently does not have any meaning, but is reserved for the future.
reserved,

/// Used by the PAX format to store key-value records that are only relevant
/// to the next file.
///
/// This package transparently handles these types.
xHeader,

/// Used by the PAX format to store key-value records that are relevant to all
/// subsequent files.
///
/// This package only supports parsing and composing such headers,
/// but does not currently support persisting the global state across files.
xGlobalHeader,

/// Indiates a sparse file in the GNU format
gnuSparse,

/// Used by the GNU format for a meta file to store the path or link name for
/// the next file.
/// This package transparently handles these types.
gnuLongName,
gnuLongLink,

/// Vendor specific typeflag, as defined in POSIX.1-1998. Seen as outdated but
/// may still exist on old files.
///
/// This library uses a single enum to catch them all.
vendor
}

/// Generates the corresponding [TypeFlag] associated with [byte].
TypeFlag typeflagFromByte(int byte) {
switch (byte) {
Expand Down
1 change: 0 additions & 1 deletion lib/src/third_party/tar/src/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:meta/meta.dart';

import 'constants.dart';
import 'header.dart';

/// An entry in a tar file.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/third_party/tar/src/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TarFormat {
int get hashCode => _value;

@override
bool operator ==(Object? other) {
bool operator ==(Object other) {
if (other is! TarFormat) return false;

return _value == other._value;
Expand Down
68 changes: 68 additions & 0 deletions lib/src/third_party/tar/src/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,74 @@ import 'exception.dart';
import 'format.dart';
import 'utils.dart';

/// Type flags for [TarHeader].
///
/// The type flag of a header indicates the kind of file associated with the
/// entry. This enum contains the various type flags over the different TAR
/// formats, and users should be careful that the type flag corresponds to the
/// TAR format they are working with.
enum TypeFlag {
/// [reg] indicates regular files.
///
/// Old tar implementations have a seperate `TypeRegA` value. This library
/// will transparently read those as [regA].
reg,

/// Legacy-version of [reg] in old tar implementations.
///
/// This is only used internally.
regA,

/// Hard link - header-only, may not have a data body
link,

/// Symbolic link - header-only, may not have a data body
symlink,

/// Character device node - header-only, may not have a data body
char,

/// Block device node - header-only, may not have a data body
block,

/// Directory - header-only, may not have a data body
dir,

/// FIFO node - header-only, may not have a data body
fifo,

/// Currently does not have any meaning, but is reserved for the future.
reserved,

/// Used by the PAX format to store key-value records that are only relevant
/// to the next file.
///
/// This package transparently handles these types.
xHeader,

/// Used by the PAX format to store key-value records that are relevant to all
/// subsequent files.
///
/// This package only supports parsing and composing such headers,
/// but does not currently support persisting the global state across files.
xGlobalHeader,

/// Indiates a sparse file in the GNU format
gnuSparse,

/// Used by the GNU format for a meta file to store the path or link name for
/// the next file.
/// This package transparently handles these types.
gnuLongName,
gnuLongLink,

/// Vendor specific typeflag, as defined in POSIX.1-1998. Seen as outdated but
/// may still exist on old files.
///
/// This library uses a single enum to catch them all.
vendor
}

/// Header of a tar entry
///
/// A tar header stores meta-information about the matching tar entry, such as
Expand Down
3 changes: 2 additions & 1 deletion lib/src/third_party/tar/src/sparse.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@internal
import 'package:async/async.dart';
import 'package:meta/meta.dart';

Expand All @@ -21,7 +22,7 @@ class SparseEntry {
String toString() => 'offset: $offset, length $length';

@override
bool operator ==(Object? other) {
bool operator ==(Object other) {
if (other is! SparseEntry) return false;

return offset == other.offset && length == other.length;
Expand Down
25 changes: 20 additions & 5 deletions lib/src/third_party/tar/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@internal
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';

import 'package:meta/meta.dart';

import 'charcodes.dart';
import 'constants.dart';
import 'exception.dart';
Expand Down Expand Up @@ -95,7 +98,7 @@ extension ByteBufferUtils on Uint8List {
int computeUnsignedHeaderChecksum() {
// Accessing the last element first helps the VM eliminate bounds checks in
// the loops below.
this[blockSize - 1];
this[blockSize - 1]; // ignore: unnecessary_statements
var result = checksumLength * _checksumPlaceholder;

for (var i = 0; i < checksumOffset; i++) {
Expand All @@ -109,7 +112,7 @@ extension ByteBufferUtils on Uint8List {
}

int computeSignedHeaderChecksum() {
this[blockSize - 1];
this[blockSize - 1]; // ignore: unnecessary_statements
// Note that _checksumPlaceholder.toSigned(8) == _checksumPlaceholder
var result = checksumLength * _checksumPlaceholder;

Expand Down Expand Up @@ -445,7 +448,7 @@ class BlockReader {

var state = _StreamState.initial;

/// Sends trailing data to the stream. Reeturns true if the subscription
/// Sends trailing data to the stream. Returns true if the subscription
/// should still be resumed afterwards.
bool emitTrailing() {
// Attempt to serve requests from pending data first.
Expand Down Expand Up @@ -512,13 +515,25 @@ class BlockReader {
controller
..onListen = scheduleInitialEmit
..onPause = () {
assert(state == _StreamState.initial || state == _StreamState.attached);
assert(
state == _StreamState.initial ||
state == _StreamState.attached ||
state == _StreamState.done,
'Unexpected pause event in $state ($_remainingBlocksInOutgoing blocks remaining).');

if (state == _StreamState.initial) {
state = _StreamState.pausedAfterInitial;
} else {
} else if (state == _StreamState.attached) {
_pause();
state = _StreamState.pausedAfterAttached;
} else if (state == _StreamState.done) {
// It may happen that onPause is called in a state where we believe
// the stream to be done already. After the stream is done, we close
// the controller in a new microtask. So if the subscription is paused
// after the last event it emitted but before we close the controller,
// we can get a pause event here.
// There's nothing to do in that case.
assert(_subscription?.isPaused != false);
}
}
..onResume = () {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/third_party/tar/tar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ library tar;
import 'src/reader.dart';
import 'src/writer.dart';

export 'src/constants.dart' show TypeFlag;
export 'src/entry.dart' show TarEntry, SynchronousTarEntry;
export 'src/exception.dart';
export 'src/format.dart';
export 'src/header.dart' show TarHeader;
export 'src/header.dart' show TarHeader, TypeFlag;
export 'src/reader.dart' show TarReader;
export 'src/writer.dart';