Install Linux updates in place and restart
The Linux app now downloads the release archive to a temporary folder, verifies its checksum, extracts it beside the install folder, swaps the bundle in with two renames (keeping <install>.previous for rollback) and relaunches. A read-only install location is reported with how to fix it. The prompt and Settings button say "Install and restart".
This commit is contained in:
@@ -5,18 +5,24 @@ import 'package:pipelines_app/features/updates/launch_update.dart';
|
||||
void main() {
|
||||
test('web compares release identity and ignores Android metadata', () {
|
||||
expect(
|
||||
webUpdateFor('web-current',
|
||||
'{"schema":1,"platform":"web","buildId":"web-current"}'),
|
||||
webUpdateFor(
|
||||
'web-current',
|
||||
'{"schema":1,"platform":"web","buildId":"web-current"}',
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
webUpdateFor('web-current',
|
||||
'{"schema":1,"platform":"web","buildId":"web-new"}'),
|
||||
webUpdateFor(
|
||||
'web-current',
|
||||
'{"schema":1,"platform":"web","buildId":"web-new"}',
|
||||
),
|
||||
isA<WebLaunchUpdate>(),
|
||||
);
|
||||
expect(
|
||||
webUpdateFor('web-current',
|
||||
'{"schema":1,"platform":"android","buildId":"web-new"}'),
|
||||
webUpdateFor(
|
||||
'web-current',
|
||||
'{"schema":1,"platform":"android","buildId":"web-new"}',
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(webUpdateFor('', '{"buildId":"web-new"}'), isNull);
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/updates/linux_self_update.dart';
|
||||
|
||||
/// Builds a release-shaped archive: pipelines-linux-x64/{pipelines-app,data/flutter_assets,lib}.
|
||||
Future<File> _archive(
|
||||
Directory root,
|
||||
String marker, {
|
||||
bool complete = true,
|
||||
}) async {
|
||||
final src = Directory('${root.path}/src-$marker/pipelines-linux-x64');
|
||||
await Directory('${src.path}/data/flutter_assets').create(recursive: true);
|
||||
if (complete) await Directory('${src.path}/lib').create();
|
||||
await File('${src.path}/pipelines-app').writeAsString(marker);
|
||||
final out = File('${root.path}/$marker.tar.gz');
|
||||
final result = await Process.run('tar', [
|
||||
'-czf',
|
||||
out.path,
|
||||
'-C',
|
||||
src.parent.path,
|
||||
'pipelines-linux-x64',
|
||||
]);
|
||||
expect(result.exitCode, 0, reason: '${result.stderr}');
|
||||
return out;
|
||||
}
|
||||
|
||||
void main() {
|
||||
late Directory root;
|
||||
late Directory install;
|
||||
|
||||
setUp(() async {
|
||||
root = await Directory.systemTemp.createTemp('linux-self-update');
|
||||
install = Directory('${root.path}/apps/pipelines');
|
||||
await Directory(
|
||||
'${install.path}/data/flutter_assets',
|
||||
).create(recursive: true);
|
||||
await Directory('${install.path}/lib').create();
|
||||
await File('${install.path}/pipelines-app').writeAsString('old');
|
||||
});
|
||||
tearDown(() => root.delete(recursive: true));
|
||||
|
||||
test('swaps in the new bundle and keeps the previous one', () async {
|
||||
final updater = LinuxSelfUpdate(installDir: install);
|
||||
expect(await updater.problem(), isNull);
|
||||
final exe = await updater.install(
|
||||
await _archive(root, 'new'),
|
||||
versionCode: 7,
|
||||
);
|
||||
expect(exe, '${install.path}/pipelines-app');
|
||||
expect(await File(exe).readAsString(), 'new');
|
||||
expect(
|
||||
await File(
|
||||
'${root.path}/apps/pipelines.previous/pipelines-app',
|
||||
).readAsString(),
|
||||
'old',
|
||||
);
|
||||
// No staging folder is left behind.
|
||||
expect(
|
||||
Directory('${root.path}/apps').listSync().map(
|
||||
(e) => e.uri.pathSegments.where((s) => s.isNotEmpty).last,
|
||||
),
|
||||
unorderedEquals(['pipelines', 'pipelines.previous']),
|
||||
);
|
||||
// A second update replaces the kept previous bundle.
|
||||
await updater.install(await _archive(root, 'newer'), versionCode: 8);
|
||||
expect(await File(exe).readAsString(), 'newer');
|
||||
expect(
|
||||
await File(
|
||||
'${root.path}/apps/pipelines.previous/pipelines-app',
|
||||
).readAsString(),
|
||||
'new',
|
||||
);
|
||||
});
|
||||
|
||||
test('an incomplete archive leaves the installed app untouched', () async {
|
||||
final updater = LinuxSelfUpdate(installDir: install);
|
||||
await expectLater(
|
||||
updater.install(
|
||||
await _archive(root, 'broken', complete: false),
|
||||
versionCode: 9,
|
||||
),
|
||||
throwsA(isA<FileSystemException>()),
|
||||
);
|
||||
expect(await File('${install.path}/pipelines-app').readAsString(), 'old');
|
||||
expect(
|
||||
Directory('${root.path}/apps/pipelines.previous').existsSync(),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('a corrupt archive is reported, not installed', () async {
|
||||
final updater = LinuxSelfUpdate(installDir: install);
|
||||
final junk = File('${root.path}/junk.tar.gz')..writeAsStringSync('nope');
|
||||
await expectLater(
|
||||
updater.install(junk, versionCode: 10),
|
||||
throwsA(
|
||||
isA<FileSystemException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
contains('could not be extracted'),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(await File('${install.path}/pipelines-app').readAsString(), 'old');
|
||||
});
|
||||
|
||||
test('a read-only install location explains how to fix it', () async {
|
||||
final apps = Directory('${root.path}/apps');
|
||||
await Process.run('chmod', ['555', apps.path]);
|
||||
addTearDown(() => Process.run('chmod', ['755', apps.path]));
|
||||
final reason = await LinuxSelfUpdate(installDir: install).problem();
|
||||
expect(reason, contains('Reinstall it in your home folder'));
|
||||
});
|
||||
}
|
||||
@@ -3,30 +3,35 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/updates/launch_update_dialog.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('desktop prompt identifies source and archive action', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => showLaunchUpdateDialog(
|
||||
context,
|
||||
web: false,
|
||||
cupertino: false,
|
||||
nativePlatform: 'linux',
|
||||
sourceName: 'Home Linux',
|
||||
for (final (platform, sentence, action) in [
|
||||
('linux', 'installs it and restarts', 'Install and restart'),
|
||||
('macos', 'extract the archive', 'Download'),
|
||||
]) {
|
||||
testWidgets('$platform prompt identifies source and its action', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => showLaunchUpdateDialog(
|
||||
context,
|
||||
web: false,
|
||||
cupertino: false,
|
||||
nativePlatform: platform,
|
||||
sourceName: 'Home Linux',
|
||||
),
|
||||
child: const Text('Check'),
|
||||
),
|
||||
child: const Text('Check'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Check'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('from Home Linux'), findsOneWidget);
|
||||
expect(find.textContaining('extract the archive'), findsOneWidget);
|
||||
expect(find.text('Download'), findsOneWidget);
|
||||
expect(find.textContaining('Android'), findsNothing);
|
||||
});
|
||||
);
|
||||
await tester.tap(find.text('Check'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('from Home Linux'), findsOneWidget);
|
||||
expect(find.textContaining(sentence), findsOneWidget);
|
||||
expect(find.text(action), findsOneWidget);
|
||||
expect(find.textContaining('Android'), findsNothing);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user