Merge pull request #33 from ente-io/handle_deleted_files_from_cache

Gracefully handle deletion of files in app cache
This commit is contained in:
Vishnu Mohandas 2021-09-09 11:34:17 +05:30 committed by GitHub
commit d5dc4e23d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View file

@ -148,7 +148,7 @@ Future<void> _init(bool isBackground) async {
await RemoteSyncService.instance.init();
await SyncService.instance.init();
await MemoriesService.instance.init();
LocalSettings.instance.init();
await LocalSettings.instance.init();
FeatureFlagService.instance.init();
_logger.info("Initialization done");
_initializationStatus.complete();

View file

@ -274,7 +274,10 @@ Future<List<String>> _tryDeleteSharedMediaFiles(List<String> localIDs) {
"/" +
id.replaceAll(kSharedMediaIdentifier, '');
try {
await io.File(localPath).delete();
// verify the file exists as the OS may have already deleted it from cache
if (io.File(localPath).existsSync()) {
await io.File(localPath).delete();
}
actuallyDeletedIDs.add(id);
} catch (e, s) {
_logger.warning("Could not delete file " + id, e, s);

View file

@ -18,11 +18,11 @@ class LocalSettings {
}
AlbumSortKey albumSortKey() {
return AlbumSortKey.values[_prefs?.getInt(kCollectionSortPref) ?? 0] ??
return AlbumSortKey.values[_prefs.getInt(kCollectionSortPref) ?? 0] ??
AlbumSortKey.lastUpdated;
}
void setAlbumSortKey(AlbumSortKey key) {
_prefs?.setInt(kCollectionSortPref, key.index);
_prefs.setInt(kCollectionSortPref, key.index);
}
}