mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-10 09:46:40 +02:00
handle move and delete of remote folders in monitor mode
This commit is contained in:
parent
9bedec0d7c
commit
4ebc4a8544
30
src/itemdb.d
30
src/itemdb.d
|
@ -1,8 +1,9 @@
|
|||
import std.datetime, std.path, std.exception, std.string;
|
||||
import std.datetime;
|
||||
import std.exception;
|
||||
import std.path;
|
||||
import std.string;
|
||||
import sqlite;
|
||||
|
||||
import std.stdio;
|
||||
|
||||
enum ItemType
|
||||
{
|
||||
file,
|
||||
|
@ -149,7 +150,6 @@ final class ItemDatabase
|
|||
Item currItem;
|
||||
path = "root/" ~ path.chompPrefix(".");
|
||||
auto s = db.prepare("SELECT * FROM item WHERE name IS ?1 AND parentDriveId IS ?2 AND parentId IS ?3");
|
||||
writeln("selectByPath " ~ path);
|
||||
foreach (name; pathSplitter(path)) {
|
||||
s.bind(1, name);
|
||||
s.bind(2, currItem.driveId);
|
||||
|
@ -165,7 +165,24 @@ final class ItemDatabase
|
|||
currItem = child;
|
||||
}
|
||||
}
|
||||
writeln(currItem.id);
|
||||
}
|
||||
item = currItem;
|
||||
return true;
|
||||
}
|
||||
|
||||
// same as selectByPath() but it does not traverse remote folders
|
||||
bool selectByPathNoRemote(const(char)[] path, out Item item)
|
||||
{
|
||||
Item currItem;
|
||||
path = "root/" ~ path.chompPrefix(".");
|
||||
auto s = db.prepare("SELECT * FROM item WHERE name IS ?1 AND parentDriveId IS ?2 AND parentId IS ?3");
|
||||
foreach (name; pathSplitter(path)) {
|
||||
s.bind(1, name);
|
||||
s.bind(2, currItem.driveId);
|
||||
s.bind(3, currItem.id);
|
||||
auto r = s.exec();
|
||||
if (r.empty) return false;
|
||||
currItem = buildItem(r);
|
||||
}
|
||||
item = currItem;
|
||||
return true;
|
||||
|
@ -242,7 +259,6 @@ final class ItemDatabase
|
|||
Item item;
|
||||
auto s = db.prepare("SELECT * FROM item WHERE driveId = ?1 AND id = ?2");
|
||||
auto s2 = db.prepare("SELECT driveId, id FROM item WHERE remoteDriveId = ?1 AND remoteId = ?2");
|
||||
writeln("computePath " ~ id);
|
||||
while (true) {
|
||||
s.bind(1, driveId);
|
||||
s.bind(2, id);
|
||||
|
@ -273,7 +289,6 @@ final class ItemDatabase
|
|||
else path = path[4 .. $];
|
||||
// special case of computing the path of the root itself
|
||||
if (path.length == 0) path = ".";
|
||||
writeln(path);
|
||||
break;
|
||||
} else {
|
||||
// remote folder
|
||||
|
@ -285,7 +300,6 @@ final class ItemDatabase
|
|||
assert(0);
|
||||
}
|
||||
}
|
||||
writeln(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -663,6 +663,10 @@ final class SyncEngine
|
|||
if (!itemdb.selectByPath(from, fromItem)) {
|
||||
throw new SyncException("Can't move an unsynced item");
|
||||
}
|
||||
if (fromItem.parentId == null) {
|
||||
// the item is a remote folder, need to do the operation on the parent
|
||||
enforce(itemdb.selectByPathNoRemote(from, fromItem));
|
||||
}
|
||||
if (itemdb.selectByPath(to, toItem)) {
|
||||
// the destination has been overwritten
|
||||
uploadDeleteItem(toItem, to);
|
||||
|
@ -697,6 +701,10 @@ final class SyncEngine
|
|||
if (!itemdb.selectByPath(path, item)) {
|
||||
throw new SyncException("Can't delete an unsynced item");
|
||||
}
|
||||
if (item.parentId == null) {
|
||||
// the item is a remote folder, need to do the operation on the parent
|
||||
enforce(itemdb.selectByPathNoRemote(path, item));
|
||||
}
|
||||
try {
|
||||
uploadDeleteItem(item, path);
|
||||
} catch (OneDriveException e) {
|
||||
|
|
Loading…
Reference in a new issue