Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore outdated ratings cache #1882

Merged
Merged
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
12 changes: 11 additions & 1 deletion packages/app_center/lib/snapd/cache_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:snapd/snapd.dart';
import 'package:ubuntu_logger/ubuntu_logger.dart';
import 'package:xdg_directories/xdg_directories.dart' as xdg;

@visibleForTesting
final cachePath =
'${xdg.cacheHome.path}/${p.basename(Platform.resolvedExecutable)}/snapd';

final _log = Logger('cache_file');

class CacheFile {
CacheFile(
String path, {
Expand Down Expand Up @@ -109,7 +112,14 @@ class CacheFile {

Future<RatingsData?> readRatingsData() async {
final data = await read() as Map?;
return data != null ? RatingsData.fromJson(data.cast()) : null;
if (data == null) return null;

try {
return RatingsData.fromJson(data.cast());
} on Error catch (e) {
_log.debug('Caught error while reading ratings cache data: $e');
return null;
}
}

void writeRatingsDataSync(RatingsData ratingsData) {
Expand Down
Loading