mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-13 03:12:37 +02:00
Fix renaming of files sync issues (#252)
* issue #249 do not safeRename the target if it is in sync * issue #249 only remove actual path if the associated ids agree
This commit is contained in:
parent
11138602ed
commit
0d05274f32
31
src/sync.d
31
src/sync.d
|
@ -740,10 +740,23 @@ final class SyncEngine
|
||||||
if (oldPath != newPath) {
|
if (oldPath != newPath) {
|
||||||
log.log("Moving ", oldPath, " to ", newPath);
|
log.log("Moving ", oldPath, " to ", newPath);
|
||||||
if (exists(newPath)) {
|
if (exists(newPath)) {
|
||||||
|
Item localNewItem;
|
||||||
|
if (itemdb.selectByPath(newPath, defaultDriveId, localNewItem)) {
|
||||||
|
if (isItemSynced(localNewItem, newPath)) {
|
||||||
|
log.vlog("Destination is in sync and will be overwritten");
|
||||||
|
} else {
|
||||||
// TODO: force remote sync by deleting local item
|
// TODO: force remote sync by deleting local item
|
||||||
log.vlog("The destination is occupied, renaming the conflicting file...");
|
log.vlog("The destination is occupied, renaming the conflicting file...");
|
||||||
safeRename(newPath);
|
safeRename(newPath);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// to be overwritten item is not already in the itemdb, so it should
|
||||||
|
// be synced. Do a safe rename here, too.
|
||||||
|
// TODO: force remote sync by deleting local item
|
||||||
|
log.vlog("The destination is occupied by new file, renaming the conflicting file...");
|
||||||
|
safeRename(newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
rename(oldPath, newPath);
|
rename(oldPath, newPath);
|
||||||
}
|
}
|
||||||
// handle changed content and mtime
|
// handle changed content and mtime
|
||||||
|
@ -853,14 +866,30 @@ final class SyncEngine
|
||||||
Item item;
|
Item item;
|
||||||
if (!itemdb.selectById(i[0], i[1], item)) continue; // check if the item is in the db
|
if (!itemdb.selectById(i[0], i[1], item)) continue; // check if the item is in the db
|
||||||
string path = itemdb.computePath(i[0], i[1]);
|
string path = itemdb.computePath(i[0], i[1]);
|
||||||
log.log("Deleting item ", path);
|
log.log("Trying to delete item ", path);
|
||||||
itemdb.deleteById(item.driveId, item.id);
|
itemdb.deleteById(item.driveId, item.id);
|
||||||
if (item.remoteDriveId != null) {
|
if (item.remoteDriveId != null) {
|
||||||
// delete the linked remote folder
|
// delete the linked remote folder
|
||||||
itemdb.deleteById(item.remoteDriveId, item.remoteId);
|
itemdb.deleteById(item.remoteDriveId, item.remoteId);
|
||||||
}
|
}
|
||||||
|
bool needsRemoval = false;
|
||||||
if (exists(path)) {
|
if (exists(path)) {
|
||||||
// path exists on the local system
|
// path exists on the local system
|
||||||
|
// make sure that the path refers to the correct item
|
||||||
|
Item pathItem;
|
||||||
|
if (itemdb.selectByPath(path, item.driveId, pathItem)) {
|
||||||
|
if (pathItem.id == item.id) {
|
||||||
|
needsRemoval = true;
|
||||||
|
} else {
|
||||||
|
log.log("Skipped due to id difference!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// item has disappeared completely
|
||||||
|
needsRemoval = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needsRemoval) {
|
||||||
|
log.log("Deleting item ", path);
|
||||||
if (isFile(path)) {
|
if (isFile(path)) {
|
||||||
remove(path);
|
remove(path);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue