pkgctl.dart 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../base/process.dart';

import 'fuchsia_device.dart';
import 'fuchsia_pm.dart';

/// Simple wrapper for interacting with the 'pkgctl' tool running on the
/// Fuchsia device.
class FuchsiaPkgctl {
  /// Teaches pkgctl on [device] about the Fuchsia package server
  Future<bool> addRepo(
      FuchsiaDevice device, FuchsiaPackageServer server) async {
    final String localIp = await device.hostAddress;
    final String configUrl = 'http://[$localIp]:${server.port}/config.json';
    final RunResult result =
        await device.shell('pkgctl repo add url -n ${server.name} $configUrl');
    return result.exitCode == 0;
  }

  /// Instructs pkgctl instance running on [device] to forget about the
  /// Fuchsia package server with the given name
  /// pkgctl repo rm fuchsia-pkg://mycorp.com
  Future<bool> rmRepo(FuchsiaDevice device, FuchsiaPackageServer server) async {
    final RunResult result = await device.shell(
      'pkgctl repo rm fuchsia-pkg://${server.name}',
    );
    return result.exitCode == 0;
  }

  /// Instructs the pkgctl instance running on [device] to prefetch the package
  /// with the given [packageUrl] hosted in the given [serverName].
  Future<bool> resolve(
    FuchsiaDevice device,
    String serverName,
    String packageName,
  ) async {
    final String packageUrl = 'fuchsia-pkg://$serverName/$packageName';
    final RunResult result = await device.shell('pkgctl resolve $packageUrl');
    return result.exitCode == 0;
  }
}