Skip to content

Commit

Permalink
Fix spdx license updater + remove package:archive dependency. (#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored May 17, 2024
1 parent 53b5425 commit bdf59b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dev_dependencies:
source_gen: ^1.0.0
test_descriptor: ^2.0.0
test_process: ^2.0.0
archive: ^3.1.2

executables:
pana:
39 changes: 17 additions & 22 deletions third_party/spdx/update_licenses.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;

const _spdxPath = 'lib/src/third_party/spdx';
const _targetPath = '$_spdxPath/licenses';
Expand All @@ -14,17 +13,26 @@ void main() async {
final client = http.Client();
final licenseDirectory = Directory(_targetPath);
final response = await client.get(Uri.parse(downloadUrl));
final decoder = ZipDecoder();

if (response.statusCode != 200) {
print('Error downloading files');
print(response.statusCode);
return;
exit(-1);
}

await _emptyDirectory(licenseDirectory);
await writeFiles(decoder.decodeBytes(response.bodyBytes));
await removeUnnecessaryFiles();
final masterZip = File(p.join(_targetPath, 'master.zip'));
await masterZip.writeAsBytes(response.bodyBytes);
final pr = await Process.run('unzip', ['-q', 'master.zip'],
workingDirectory: _targetPath);
if (pr.exitCode != 0) {
print('Error extracting files.');
print(pr.stdout);
print(pr.stderr);
exit(-1);
}
await masterZip.delete();
await _removeUnnecessaryFiles();
}

Future<void> _emptyDirectory(Directory dir) async {
Expand All @@ -34,23 +42,10 @@ Future<void> _emptyDirectory(Directory dir) async {
await dir.create(recursive: true);
}

Future<void> writeFiles(Archive archive) async {
for (var f in archive.files) {
if (f.isFile) {
final name = f.name;
final file = File('$_targetPath/$name');
await file.create();
await file.writeAsBytes(f.content as Uint8List);
} else {
await Directory('$_targetPath/${f.name}').create(recursive: true);
}
}
}

Future<void> removeUnnecessaryFiles() async {
Future<void> _removeUnnecessaryFiles() async {
final jsonDirectory =
Directory('$_targetPath/license-list-data-master/json/details/');
final spdxDirectory = Directory('$_targetPath/license-list-data-master');
Directory('$_targetPath/license-list-data-main/json/details/');
final spdxDirectory = Directory('$_targetPath/license-list-data-main');
final entities = jsonDirectory.listSync();

final licenses = <_LicenseData>[];
Expand Down

0 comments on commit bdf59b4

Please sign in to comment.