updateTo method

FutureOr<ReleaseUpdateResult?> updateTo(
  1. ReleaseBundle bundle, {
  2. bool force = false,
  3. bool verbose = false,
})

Updates the current stored version to the bundle.

Implementation

FutureOr<ReleaseUpdateResult?> updateTo(ReleaseBundle bundle,
    {bool force = false, bool verbose = false}) async {
  var currentRelease = await this.currentRelease;
  var release = bundle.release;

  if (!force && currentRelease == release) return null;

  var files = await bundle.files;

  var manifest = await bundle.buildManifest();

  var savedFiles = <ReleaseFile>[];

  if (files.isNotEmpty) {
    if (verbose) {
      print('»  Saving release `$release` files (${files.length}):');
    }

    for (var f in files) {
      var manifestFile = manifest.getFileByPath(f.filePath);

      if (manifestFile != null) {
        var storedFileEquals = await isFileEquals(release, f, manifestFile);
        if (storedFileEquals) {
          if (verbose) {
            print('   »  Skipping unchanged file: ${f.filePath}');
          }
          continue;
        }
      }

      var ok = await saveFile(release, f, verbose: verbose);
      if (!ok) {
        throw StateError("Can't save file: $f");
      }

      savedFiles.add(f);
    }
  }

  var ok = await saveRelease(release);
  if (!ok) {
    throw StateError("Can't save release: $release");
  }

  ok = await saveManifest(manifest);
  if (!ok) {
    throw StateError("Can't save manifest!");
  }

  ok = await checkManifest(manifest, verbose: true);
  if (!ok) {
    throw StateError("Error checking Manifest!");
  }

  var result = ReleaseUpdateResult(release, manifest, savedFiles);
  return result;
}