mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-19 14:16:36 +02:00
Fix that folders are renamed despite using --dry-run (#2343)
* Fix that folders are renamed despite using --dry-run
This commit is contained in:
parent
0838651327
commit
00ce7eed0e
43
src/sync.d
43
src/sync.d
|
@ -231,8 +231,10 @@ final class SyncEngine
|
||||||
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[2][] idsToDelete;
|
private string[2][] idsToDelete;
|
||||||
// list of items we fake created when running --dry-run
|
// list of items we fake created when using --dry-run
|
||||||
private string[2][] idsFaked;
|
private string[2][] idsFaked;
|
||||||
|
// list of directory names changed online, but not changed locally when using --dry-run
|
||||||
|
private string[] pathsRenamed;
|
||||||
// default drive id
|
// default drive id
|
||||||
private string defaultDriveId;
|
private string defaultDriveId;
|
||||||
// default root id
|
// default root id
|
||||||
|
@ -1802,7 +1804,7 @@ final class SyncEngine
|
||||||
// are there any delta changes?
|
// are there any delta changes?
|
||||||
if (("value" in changesAvailable) != null) {
|
if (("value" in changesAvailable) != null) {
|
||||||
deltaChanges = count(changesAvailable["value"].array);
|
deltaChanges = count(changesAvailable["value"].array);
|
||||||
log.log("changesAvailable query reports that there are " , deltaChanges , " changes that need processing on OneDrive");
|
log.vdebug("changesAvailable query reports that there are " , deltaChanges , " changes that need processing on OneDrive");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
|
@ -2907,20 +2909,32 @@ final class SyncEngine
|
||||||
} else {
|
} 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);
|
if (!dryRun) {
|
||||||
|
safeRename(newPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// to be overwritten item is not already in the itemdb, so it should
|
// to be overwritten item is not already in the itemdb, so it should
|
||||||
// be synced. Do a safe rename here, too.
|
// be synced. Do a safe rename here, too.
|
||||||
// TODO: force remote sync by deleting local item
|
// TODO: force remote sync by deleting local item
|
||||||
log.vlog("The destination is occupied by new file, renaming the conflicting file...");
|
log.vlog("The destination is occupied by new file, renaming the conflicting file...");
|
||||||
safeRename(newPath);
|
if (!dryRun) {
|
||||||
|
safeRename(newPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// try and rename path, catch exception
|
// try and rename path, catch exception
|
||||||
try {
|
try {
|
||||||
log.vdebug("Calling rename(oldPath, newPath)");
|
log.vdebug("Calling rename(oldPath, newPath)");
|
||||||
rename(oldPath, newPath);
|
if (!dryRun) {
|
||||||
|
// rename physical path on disk
|
||||||
|
rename(oldPath, newPath);
|
||||||
|
} else {
|
||||||
|
// track this as a faked id item
|
||||||
|
idsFaked ~= [newItem.driveId, newItem.id];
|
||||||
|
// we also need to track that we did not rename this path
|
||||||
|
pathsRenamed ~= [oldPath];
|
||||||
|
}
|
||||||
} catch (FileException e) {
|
} catch (FileException e) {
|
||||||
// display the error message
|
// display the error message
|
||||||
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
|
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
|
||||||
|
@ -4449,8 +4463,23 @@ final class SyncEngine
|
||||||
log.logAndNotify("Skipping item - invalid name (Microsoft Naming Convention): ", path);
|
log.logAndNotify("Skipping item - invalid name (Microsoft Naming Convention): ", path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to upload this new item
|
// If we are in a --dry-run scenario, we may have renamed a folder - but it is technically not renamed locally
|
||||||
|
// Thus, that entire path may be attemtped to be uploaded as new data to OneDrive
|
||||||
|
if (dryRun) {
|
||||||
|
// check the pathsRenamed array for this path
|
||||||
|
// if any match - we need to exclude this path
|
||||||
|
foreach (thisRenamedPath; pathsRenamed) {
|
||||||
|
log.vdebug("Renamed Path to evaluate: ", thisRenamedPath);
|
||||||
|
// Can we find 'thisRenamedPath' in the given 'path'
|
||||||
|
if (canFind(path, thisRenamedPath)) {
|
||||||
|
log.vdebug("Renamed Path MATCH - DONT UPLOAD AS NEW");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We want to upload this new local data
|
||||||
if (isDir(path)) {
|
if (isDir(path)) {
|
||||||
Item item;
|
Item item;
|
||||||
bool pathFoundInDB = false;
|
bool pathFoundInDB = false;
|
||||||
|
|
Loading…
Reference in a new issue