Skip to content
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
20 changes: 7 additions & 13 deletions app/lib/tool/test_profile/import_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,22 @@ class ArchiveBuilder {
final _entries = <TarEntry>[];

void addFile(String path, String content) {
final bytes = utf8.encode(content);
_entries.add(
TarEntry(
TarHeader(
name: path,
size: bytes.length,
mode: 420, // 644₈
),
Stream<List<int>>.fromIterable([bytes]),
),
);
addFileBytes(path, utf8.encode(content));
}

void addFileBytes(String path, List<int> bytes) {
addFileByteChunks(path, [bytes]);
}

void addFileByteChunks(String path, List<List<int>> chunks) {
_entries.add(
TarEntry(
TarHeader(
name: path,
size: bytes.length,
size: chunks.fold<int>(0, (a, b) => a + b.length),
mode: 420, // 644₈
),
Stream<List<int>>.fromIterable([bytes]),
Stream<List<int>>.fromIterable(chunks),
),
);
}
Expand Down
14 changes: 8 additions & 6 deletions app/lib/tool/test_profile/importer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import '../../fake/backend/fake_auth_provider.dart';
import '../../frontend/handlers/pubapi.client.dart';
import '../../service/async_queue/async_queue.dart';
import '../../shared/configuration.dart';
import '../../shared/utils.dart';
import '../utils/pub_api_client.dart';
import 'import_source.dart';
import 'models.dart';
Expand Down Expand Up @@ -294,14 +293,17 @@ Future<List<int>> _mayCleanupTarModeBits(List<int> bytes) async {
var needsUpdate = false;
while (await tarReader.moveNext()) {
final current = tarReader.current;
if (current.header.mode != 420) {
if (current.header.mode & 420 != 420) {
// 644₈
needsUpdate = true;
}
archiveBuilder.addFileBytes(
current.name,
await current.contents.foldBytes(),
);
if (current.header.typeFlag == TypeFlag.reg ||
current.header.typeFlag == TypeFlag.regA) {
archiveBuilder.addFileByteChunks(
current.name,
await current.contents.toList(),
);
}
}
return needsUpdate ? archiveBuilder.toTarGzBytes() : bytes;
}