Skip to content

Commit 56d3d61

Browse files
committed
Fix and improve test_profile import.
1 parent 53b8a9c commit 56d3d61

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

app/lib/tool/test_profile/import_source.dart

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,28 +183,22 @@ class ArchiveBuilder {
183183
final _entries = <TarEntry>[];
184184

185185
void addFile(String path, String content) {
186-
final bytes = utf8.encode(content);
187-
_entries.add(
188-
TarEntry(
189-
TarHeader(
190-
name: path,
191-
size: bytes.length,
192-
mode: 420, // 644₈
193-
),
194-
Stream<List<int>>.fromIterable([bytes]),
195-
),
196-
);
186+
addFileBytes(path, utf8.encode(content));
197187
}
198188

199189
void addFileBytes(String path, List<int> bytes) {
190+
addFileByteChunks(path, [bytes]);
191+
}
192+
193+
void addFileByteChunks(String path, List<List<int>> chunks) {
200194
_entries.add(
201195
TarEntry(
202196
TarHeader(
203197
name: path,
204-
size: bytes.length,
198+
size: chunks.fold<int>(0, (a, b) => a + b.length),
205199
mode: 420, // 644₈
206200
),
207-
Stream<List<int>>.fromIterable([bytes]),
201+
Stream<List<int>>.fromIterable(chunks),
208202
),
209203
);
210204
}

app/lib/tool/test_profile/importer.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import '../../fake/backend/fake_auth_provider.dart';
1818
import '../../frontend/handlers/pubapi.client.dart';
1919
import '../../service/async_queue/async_queue.dart';
2020
import '../../shared/configuration.dart';
21-
import '../../shared/utils.dart';
2221
import '../utils/pub_api_client.dart';
2322
import 'import_source.dart';
2423
import 'models.dart';
@@ -294,14 +293,17 @@ Future<List<int>> _mayCleanupTarModeBits(List<int> bytes) async {
294293
var needsUpdate = false;
295294
while (await tarReader.moveNext()) {
296295
final current = tarReader.current;
297-
if (current.header.mode != 420) {
296+
if (current.header.mode & 420 != 420) {
298297
// 644₈
299298
needsUpdate = true;
300299
}
301-
archiveBuilder.addFileBytes(
302-
current.name,
303-
await current.contents.foldBytes(),
304-
);
300+
if (current.header.typeFlag == TypeFlag.reg ||
301+
current.header.typeFlag == TypeFlag.regA) {
302+
archiveBuilder.addFileByteChunks(
303+
current.name,
304+
await current.contents.toList(),
305+
);
306+
}
305307
}
306308
return needsUpdate ? archiveBuilder.toTarGzBytes() : bytes;
307309
}

0 commit comments

Comments
 (0)