Gracefully handle deletion of unsynced files
This commit is contained in:
parent
bb95979bb6
commit
830e83e3bb
7 changed files with 28 additions and 14 deletions
|
@ -639,13 +639,22 @@ class FilesDB {
|
|||
);
|
||||
}
|
||||
|
||||
Future<int> deleteLocalFile(String localID) async {
|
||||
Future<int> deleteLocalFile(File file) async {
|
||||
final db = await instance.database;
|
||||
return db.delete(
|
||||
table,
|
||||
where: '$columnLocalID =?',
|
||||
whereArgs: [localID],
|
||||
);
|
||||
if (file.localID != null) {
|
||||
// delete all files with same local ID
|
||||
return db.delete(
|
||||
table,
|
||||
where: '$columnLocalID =?',
|
||||
whereArgs: [file.localID],
|
||||
);
|
||||
} else {
|
||||
return db.delete(
|
||||
table,
|
||||
where: '$columnGeneratedID =?',
|
||||
whereArgs: [file.generatedID],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteLocalFiles(List<String> localIDs) async {
|
||||
|
|
|
@ -62,6 +62,9 @@ class File {
|
|||
}
|
||||
|
||||
Future<AssetEntity> getAsset() {
|
||||
if (localID == null) {
|
||||
return Future.value(null);
|
||||
}
|
||||
return AssetEntity.fromId(localID);
|
||||
}
|
||||
|
||||
|
|
|
@ -320,9 +320,11 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
|
|||
newFile.collectionID = widget.originalFile.collectionID;
|
||||
newFile.location = widget.originalFile.location;
|
||||
if (!newFile.hasLocation() && widget.originalFile.localID != null) {
|
||||
final latLong =
|
||||
await (await widget.originalFile.getAsset()).latlngAsync();
|
||||
newFile.location = Location(latLong.latitude, latLong.longitude);
|
||||
var assetEntity = await widget.originalFile.getAsset();
|
||||
if (assetEntity != null) {
|
||||
final latLong = await assetEntity.latlngAsync();
|
||||
newFile.location = Location(latLong.latitude, latLong.longitude);
|
||||
}
|
||||
}
|
||||
newFile.generatedID = await FilesDB.instance.insert(newFile);
|
||||
await LocalSyncService.instance.trackEditedFile(newFile);
|
||||
|
|
|
@ -180,7 +180,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
_loadNetworkImage();
|
||||
} else {
|
||||
_logger.info("Deleting file " + widget.file.tag());
|
||||
FilesDB.instance.deleteLocalFile(widget.file.localID);
|
||||
FilesDB.instance.deleteLocalFile(widget.file);
|
||||
Bus.instance.fire(LocalPhotosUpdatedEvent([widget.file]));
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -150,7 +150,7 @@ class _ZoomableImageState extends State<ZoomableImage>
|
|||
FilesDB.instance.update(_photo);
|
||||
_loadNetworkImage();
|
||||
} else {
|
||||
FilesDB.instance.deleteLocalFile(_photo.localID);
|
||||
FilesDB.instance.deleteLocalFile(_photo);
|
||||
Bus.instance.fire(LocalPhotosUpdatedEvent([_photo]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ Future<void> deleteFilesFromEverywhere(
|
|||
uploadedFileIDsToBeDeleted.add(file.uploadedFileID);
|
||||
updatedCollectionIDs.add(file.collectionID);
|
||||
} else {
|
||||
await FilesDB.instance.deleteLocalFile(file.localID);
|
||||
await FilesDB.instance.deleteLocalFile(file);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -288,4 +288,4 @@ Future<List<String>> _tryDeleteSharedMediaFiles(List<String> localIDs) {
|
|||
_logger.severe("Unexpected error while deleting share media files", e, s);
|
||||
return Future.value(actuallyDeletedIDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -385,7 +385,7 @@ class FileUploader {
|
|||
|
||||
Future _onInvalidFileError(File file) async {
|
||||
_logger.warning("Invalid file encountered: " + file.toString());
|
||||
await FilesDB.instance.deleteLocalFile(file.localID);
|
||||
await FilesDB.instance.deleteLocalFile(file);
|
||||
await LocalSyncService.instance.trackInvalidFile(file);
|
||||
throw InvalidFileError();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue