Fix deletion behavior
This commit is contained in:
parent
e3329805ac
commit
49af595268
3 changed files with 19 additions and 1 deletions
|
@ -120,6 +120,9 @@ class FilesDB {
|
|||
final db = await instance.database;
|
||||
final results = await db.query(table,
|
||||
where: '$columnGeneratedID = ?', whereArgs: [generatedID]);
|
||||
if (results.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return _convertToFiles(results)[0];
|
||||
}
|
||||
|
||||
|
@ -386,6 +389,15 @@ class FilesDB {
|
|||
);
|
||||
}
|
||||
|
||||
Future<int> deleteLocalFile(String localID) async {
|
||||
final db = await instance.database;
|
||||
return db.delete(
|
||||
table,
|
||||
where: '$columnLocalID =?',
|
||||
whereArgs: [localID],
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> deleteFromCollection(int uploadedFileID, int collectionID) async {
|
||||
final db = await instance.database;
|
||||
return db.delete(
|
||||
|
|
|
@ -218,7 +218,11 @@ class SyncService {
|
|||
.getOrCreateForPath(file.deviceFolder))
|
||||
.id;
|
||||
final existingFile = await _db.getFile(file.generatedID);
|
||||
|
||||
if (existingFile == null) {
|
||||
// File was deleted locally while being uploaded
|
||||
await _deleteFileOnServer(file.uploadedFileID);
|
||||
continue;
|
||||
}
|
||||
if (existingFile.uploadedFileID != null) {
|
||||
// The file was uploaded outside this loop
|
||||
// Eg: Addition to an album or favorites
|
||||
|
|
|
@ -37,6 +37,8 @@ Future<void> deleteFiles(List<File> files) async {
|
|||
if (file.uploadedFileID != null) {
|
||||
hasUploadedFiles = true;
|
||||
await FilesDB.instance.markForDeletion(file.uploadedFileID);
|
||||
} else {
|
||||
await FilesDB.instance.deleteLocalFile(file.localID);
|
||||
}
|
||||
}
|
||||
await PhotoManager.editor.deleteWithIds(localIDs);
|
||||
|
|
Loading…
Add table
Reference in a new issue