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
29 changes: 29 additions & 0 deletions example/install_files.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:async';
import 'package:packagekit/packagekit.dart';

void main(List<String> args) async {
if (args.isEmpty) {
print('Need package paths(s)');
return;
}
var paths = args;

var client = PackageKitClient();
await client.connect();

var installTransaction = await client.createTransaction();
var installCompleter = Completer();
installTransaction.events.listen((event) {
if (event is PackageKitPackageEvent) {
print('[${event.packageId.name}] ${event.info}');
} else if (event is PackageKitItemProgressEvent) {
print('[${event.packageId.name}] ${event.status} ${event.percentage}%');
} else if (event is PackageKitFinishedEvent) {
installCompleter.complete();
}
});
await installTransaction.installFiles(paths);
await installCompleter.future;

await client.close();
}
15 changes: 15 additions & 0 deletions lib/src/packagekit_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,21 @@ class PackageKitTransaction {
replySignature: DBusSignature(''));
}

/// Install local package files onto the local system.
/// The files are specified with their full ppaths].
/// This method generates a [PackageKitPackageEvent] event for each package that is installed.
Future<void> installFiles(Iterable<String> paths,
{Set<PackageKitTransactionFlag> transactionFlags = const {}}) async {
await _object.callMethod(
_packageKitTransactionInterfaceName,
'InstallFiles',
[
DBusUint64(_encodeTransactionFlags(transactionFlags)),
DBusArray.string(paths)
],
replySignature: DBusSignature(''));
}

/// Install new packages with [packageIds] on the local system.
/// This method generates a [PackageKitPackageEvent] event for each package that is installed.
Future<void> installPackages(Iterable<PackageKitPackageId> packageIds,
Expand Down
75 changes: 74 additions & 1 deletion test/packagekit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ class MockPackageKitTransaction extends DBusObject {
}
emitFinished(exitSuccess, server.transactionRuntime);
return DBusMethodSuccessResponse();
case 'InstallFiles':
var paths = (methodCall.values[1] as DBusArray).mapString();
for (var path in paths) {
var package = server.findAvailableFile(path);
if (package == null) {
emitFinished(exitFailed, server.transactionRuntime);
return DBusMethodSuccessResponse();
}
var id = '${package.name};${package.version};${package.arch};+manual';
emitPackage(infoPreparing, id, package.summary);
emitPackage(infoDecompressing, id, package.summary);
emitPackage(infoFinished, id, package.summary);
emitPackage(infoInstalling, id, package.summary);
emitPackage(infoFinished, id, package.summary);
}
emitFinished(exitSuccess, server.transactionRuntime);
return DBusMethodSuccessResponse();
case 'InstallPackages':
var packageIds = (methodCall.values[1] as DBusArray)
.children
Expand Down Expand Up @@ -452,6 +469,7 @@ class MockPackageKitServer extends DBusClient {
final List<MockRepository> repositories;
final Map<String, List<MockPackage>> availablePackages;
final List<MockPackage> installedPackages;
final Map<String, MockPackage> availableFiles;

String? lastLocale;
bool? lastBackground;
Expand All @@ -476,7 +494,8 @@ class MockPackageKitServer extends DBusClient {
this.transactionRuntime = 0,
this.repositories = const [],
this.availablePackages = const {},
this.installedPackages = const []})
this.installedPackages = const [],
this.availableFiles = const {}})
: super(clientAddress);

MockPackage? findInstalled(String packageId) {
Expand Down Expand Up @@ -516,6 +535,10 @@ class MockPackageKitServer extends DBusClient {
return null;
}

MockPackage? findAvailableFile(String path) {
return availableFiles[path];
}

Future<void> start() async {
await requestName('org.freedesktop.PackageKit');
_root = MockPackageKitRoot(this);
Expand Down Expand Up @@ -1235,6 +1258,56 @@ void main() {
await transaction.installPackages([packageId]);
});

test('install files', () async {
var server = DBusServer();
addTearDown(() async => await server.close());
var clientAddress =
await server.listenAddress(DBusAddress.unix(dir: Directory.systemTemp));

var summary = 'example package based on GNU hello';
var packagekit = MockPackageKitServer(clientAddress,
transactionRuntime: 1234,
availableFiles: {
'/hello_2.1.0-2-ubuntu4_arm64.deb':
MockPackage('hello', '2.10', arch: 'arm64', summary: summary)
});
addTearDown(() async => await packagekit.close());
await packagekit.start();

var client = PackageKitClient(bus: DBusClient(clientAddress));
addTearDown(() async => await client.close());
await client.connect();

var transaction = await client.createTransaction();
var packageId = PackageKitPackageId.fromString('hello;2.10;arm64;+manual');
expect(
transaction.events,
emitsInOrder([
PackageKitPackageEvent(
info: PackageKitInfo.preparing,
packageId: packageId,
summary: summary),
PackageKitPackageEvent(
info: PackageKitInfo.decompressing,
packageId: packageId,
summary: summary),
PackageKitPackageEvent(
info: PackageKitInfo.finished,
packageId: packageId,
summary: summary),
PackageKitPackageEvent(
info: PackageKitInfo.installing,
packageId: packageId,
summary: summary),
PackageKitPackageEvent(
info: PackageKitInfo.finished,
packageId: packageId,
summary: summary),
PackageKitFinishedEvent(exit: PackageKitExit.success, runtime: 1234)
]));
await transaction.installFiles(['/hello_2.1.0-2-ubuntu4_arm64.deb']);
});

test('remove', () async {
var server = DBusServer();
addTearDown(() async => await server.close());
Expand Down