mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-01 21:52:50 +02:00
Search all distinct drive id's rather than just default drive id for --get-file-link (#1230)
* Add new DB query to return distinct driveId's from database * Use all distinct drive ID's to query if path is in-sync with OneDrive before attempting to retreive the item file link from OneDrive
This commit is contained in:
parent
525504f91a
commit
6b0b6a66f7
14
src/itemdb.d
14
src/itemdb.d
|
@ -484,4 +484,18 @@ final class ItemDatabase
|
||||||
auto stmt = db.prepare("VACUUM;");
|
auto stmt = db.prepare("VACUUM;");
|
||||||
stmt.exec();
|
stmt.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select distinct driveId items from database
|
||||||
|
string[] selectDistinctDriveIds()
|
||||||
|
{
|
||||||
|
string[] driveIdArray;
|
||||||
|
auto stmt = db.prepare("SELECT DISTINCT driveId FROM item;");
|
||||||
|
auto res = stmt.exec();
|
||||||
|
if (res.empty) return driveIdArray;
|
||||||
|
while (!res.empty) {
|
||||||
|
driveIdArray ~= res.front[0].dup;
|
||||||
|
res.step();
|
||||||
|
}
|
||||||
|
return driveIdArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
38
src/sync.d
38
src/sync.d
|
@ -5529,25 +5529,31 @@ final class SyncEngine
|
||||||
if (exists(localFilePath)) {
|
if (exists(localFilePath)) {
|
||||||
// File exists locally, does it exist in the database
|
// File exists locally, does it exist in the database
|
||||||
// Path needs to be relative to sync_dir path
|
// Path needs to be relative to sync_dir path
|
||||||
string relativePath = relativePath(localFilePath, syncDir);
|
|
||||||
Item item;
|
Item item;
|
||||||
if (itemdb.selectByPath(relativePath, defaultDriveId, item)) {
|
string[] distinctDriveIds = itemdb.selectDistinctDriveIds();
|
||||||
// File is in the local database cache
|
string relativePath = relativePath(localFilePath, syncDir);
|
||||||
JSONValue fileDetails;
|
bool fileInDB = false;
|
||||||
|
foreach (searchDriveId; distinctDriveIds) {
|
||||||
try {
|
if (itemdb.selectByPath(relativePath, searchDriveId, item)) {
|
||||||
fileDetails = onedrive.getFileDetails(item.driveId, item.id);
|
// File is in the local database cache
|
||||||
} catch (OneDriveException e) {
|
fileInDB = true;
|
||||||
// display what the error is
|
JSONValue fileDetails;
|
||||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
try {
|
||||||
return;
|
fileDetails = onedrive.getFileDetails(item.driveId, item.id);
|
||||||
}
|
} catch (OneDriveException e) {
|
||||||
|
// display what the error is
|
||||||
|
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
|
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
|
||||||
// Valid JSON object
|
// Valid JSON object
|
||||||
writeln(fileDetails["webUrl"].str);
|
writeln(fileDetails["webUrl"].str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
// was file found?
|
||||||
|
if (!fileInDB) {
|
||||||
// File has not been synced with OneDrive
|
// File has not been synced with OneDrive
|
||||||
log.error("File has not been synced with OneDrive: ", localFilePath);
|
log.error("File has not been synced with OneDrive: ", localFilePath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue