mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-02 22:12:33 +02:00
handle moving items between drives
This commit is contained in:
parent
c54d1927e9
commit
9bedec0d7c
|
@ -190,7 +190,7 @@ void performSync(SyncEngine sync)
|
||||||
sync.applyDifferences();
|
sync.applyDifferences();
|
||||||
if (!downloadOnly) {
|
if (!downloadOnly) {
|
||||||
sync.scanForDifferences();
|
sync.scanForDifferences();
|
||||||
// HACK: file metadata are often changed by OneDrive after an upload
|
// ensure that the current state is updated
|
||||||
sync.applyDifferences();
|
sync.applyDifferences();
|
||||||
}
|
}
|
||||||
count = -1;
|
count = -1;
|
||||||
|
|
36
src/sync.d
36
src/sync.d
|
@ -655,30 +655,40 @@ final class SyncEngine
|
||||||
itemdb.upsert(item);
|
itemdb.upsert(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_move
|
||||||
void uploadMoveItem(string from, string to)
|
void uploadMoveItem(string from, string to)
|
||||||
{
|
{
|
||||||
log.log("Moving remote item: ", from, " -> ", to);
|
log.log("Moving ", from, " to ", to);
|
||||||
Item fromItem, toItem, parentItem;
|
Item fromItem, toItem, parentItem;
|
||||||
if (!itemdb.selectByPath(from, fromItem)) {
|
if (!itemdb.selectByPath(from, fromItem)) {
|
||||||
throw new SyncException("Can't move an unsynced item");
|
throw new SyncException("Can't move an unsynced item");
|
||||||
}
|
}
|
||||||
if (itemdb.selectByPath(to, toItem)) {
|
if (itemdb.selectByPath(to, toItem)) {
|
||||||
// the destination has been overridden
|
// the destination has been overwritten
|
||||||
uploadDeleteItem(toItem, to);
|
uploadDeleteItem(toItem, to);
|
||||||
}
|
}
|
||||||
if (!itemdb.selectByPath(to.dirName, parentItem)) {
|
if (!itemdb.selectByPath(dirName(to), parentItem)) {
|
||||||
throw new SyncException("Can't move an item to an unsynced directory");
|
throw new SyncException("Can't move an item to an unsynced directory");
|
||||||
}
|
}
|
||||||
JSONValue diff = ["name": baseName(to)];
|
if (fromItem.driveId != parentItem.driveId) {
|
||||||
diff["parentReference"] = JSONValue([
|
// items cannot be moved between drives
|
||||||
"id": parentItem.id
|
uploadDeleteItem(fromItem, from);
|
||||||
]);
|
uploadNewFile(to);
|
||||||
auto res = onedrive.updateById(fromItem.driveId, fromItem.id, diff, fromItem.eTag);
|
} else {
|
||||||
saveItem(res);
|
SysTime mtime = timeLastModified(to).toUTC();
|
||||||
string driveId = res["parentReference"]["driveId"].str;
|
JSONValue diff = [
|
||||||
string id = res["id"].str;
|
"name": JSONValue(baseName(to)),
|
||||||
string eTag = res["eTag"].str;
|
"parentReference": JSONValue([
|
||||||
uploadLastModifiedTime(driveId, id, eTag, timeLastModified(to).toUTC());
|
"id": parentItem.id
|
||||||
|
]),
|
||||||
|
"fileSystemInfo": JSONValue([
|
||||||
|
"lastModifiedDateTime": mtime.toISOExtString()
|
||||||
|
])
|
||||||
|
];
|
||||||
|
auto res = onedrive.updateById(fromItem.driveId, fromItem.id, diff, fromItem.eTag);
|
||||||
|
// update itemdb
|
||||||
|
saveItem(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteByPath(const(char)[] path)
|
void deleteByPath(const(char)[] path)
|
||||||
|
|
Loading…
Reference in a new issue