fixed bug that allowed files marked for deletion to be keeped

This commit is contained in:
skilion 2016-12-25 23:25:24 +01:00
parent ff58a86b7f
commit 3a10f0f4b5

View file

@ -56,7 +56,7 @@ final class SyncEngine
// list of items to skip while applying the changes // list of items to skip while applying the changes
private string[] skippedItems; private string[] skippedItems;
// list of items to delete after the changes has been downloaded // list of items to delete after the changes has been downloaded
private string[] pathsToDelete; private string[] idsToDelete;
this(Config cfg, OneDriveApi onedrive, ItemDatabase itemdb) this(Config cfg, OneDriveApi onedrive, ItemDatabase itemdb)
{ {
@ -117,8 +117,8 @@ final class SyncEngine
} catch (OneDriveException e) { } catch (OneDriveException e) {
throw new SyncException(e.msg, e); throw new SyncException(e.msg, e);
} }
// delete items in pathsToDelete // delete items in idsToDelete
if (pathsToDelete.length > 0) deleteItems(); if (idsToDelete.length > 0) deleteItems();
// empty the skipped items // empty the skipped items
skippedItems.length = 0; skippedItems.length = 0;
assumeSafeAppend(skippedItems); assumeSafeAppend(skippedItems);
@ -166,10 +166,7 @@ final class SyncEngine
ItemType type; ItemType type;
if (isItemDeleted(item)) { if (isItemDeleted(item)) {
log.vlog("The item is marked for deletion"); log.vlog("The item is marked for deletion");
if (cached) { if (cached) idsToDelete ~= id;
itemdb.deleteById(id);
pathsToDelete ~= oldPath;
}
return; return;
} else if (isItemFile(item)) { } else if (isItemFile(item)) {
type = ItemType.file; type = ItemType.file;
@ -311,7 +308,9 @@ final class SyncEngine
private void deleteItems() private void deleteItems()
{ {
log.vlog("Deleting files ..."); log.vlog("Deleting files ...");
foreach_reverse (path; pathsToDelete) { foreach_reverse (id; idsToDelete) {
string path = itemdb.computePath(id);
itemdb.deleteById(id);
if (exists(path)) { if (exists(path)) {
if (isFile(path)) { if (isFile(path)) {
remove(path); remove(path);
@ -326,8 +325,8 @@ final class SyncEngine
} }
} }
} }
pathsToDelete.length = 0; idsToDelete.length = 0;
assumeSafeAppend(pathsToDelete); assumeSafeAppend(idsToDelete);
} }
// scan the given directory for differences // scan the given directory for differences